Wednesday, July 20, 2022

[FIXED] How can I check if a 2 numbers have the same digits PowerShell?

Issue

I want to compare two int so if they contain the same digits it outputs a true,for example:

$a=1260
$b=2106

and then because both of them contain: 0126 it outputs true how can this be made? And if it's possible with the fewest possible lines


Solution

Here's one technique:

$null -eq (Compare-Object -ReferenceObject ([char[]][String]1260) -DifferenceObject ([char[]][String]2601))

Which returns true or false, depending on if the digits are the same or not.



Answered By - boxdog
Answer Checked By - Mildred Charles (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.