Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,026 questions

51,982 answers

573 users

How to implement a function that check if two arrays have the same set of digits in JavaScript

1 Answer

0 votes
function have_same_set_of_digits(arr1, arr2) {
    const len1 = arr1.length;
    const len2 = arr2.length;
      
    if (len1 != len2)
        return false;
     
    for (let i = 0; i < len1; i++) {
        let found = false;
        for (let j = 0; j < len1; j++) {
            if (arr1[i] == arr2[j]) {
                found = true;
                break;
            }
        }
        if (!found)
            return false;
    }
   
    return true;
}
     
const arr1 = [1, 3, 8, 5, 9, 2];
const arr2 = [2, 9, 1, 8, 2, 5];
        
if (have_same_set_of_digits(arr1, arr2))
     console.log("Yes");
else
     console.log("No");
  
  
    
      
      
/*
run:
      
"No"
      
*/

 



answered Feb 2, 2022 by avibootz

Related questions

1 answer 131 views
1 answer 140 views
1 answer 181 views
1 answer 138 views
2 answers 160 views
...