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.

39,884 questions

51,810 answers

573 users

How to check whether an array is subset of another array in Node.js

2 Answers

0 votes
function isSubset(arr1, arr2) {
	const size1 = arr1.length;
    const size2 = arr2.length;
    let j;
    for (let i = 0; i < size2; i++) {
        for (j = 0; j < size1; j++) {
             	if (arr2[i] == arr1[j])
                 break;
            	}
            	if (j == size1)
                	return false;
        }
        return true;
    }
    
const arr1 = [ 5, 1, 8, 12, 40, 7, 9, 100 ];
const arr2 = [ 8, 40, 9, 1 ];
 
if (isSubset(arr1, arr2))
    console.log("yes");
else
    console.log("no");
 
 
 
   
/*
run:
   
yes
   
*/

 



answered Dec 21, 2021 by avibootz
0 votes
const arr1 = [ 5, 1, 8, 12, 40, 7, 9, 100 ];
const arr2 = [ 8, 40, 9, 1 ];

const result = arr2.every(val => arr1.includes(val));

console.log(result);
 
 
 
   
/*
run:
   
true
   
*/

 



answered Dec 21, 2021 by avibootz
...