7 months ago

``````const solve = (arrOne, arrTwo) => {
return [...new Set([...arrOne, ...arrTwo])].length === arrOne.length;
};

``````

9 months ago

``````const solve = (arrOne, arrTwo) => {
const reducer = (previousValue, currentValue) => previousValue + currentValue;
return arrOne.reduce(reducer) === arrTwo.reduce(reducer);
};
``````

10 months ago

`const solve = (arrOne, arrTwo) => {

return arrOne.sort().join("") === arrTwo.sort().join("") ? true : false

};`

a year ago

I naively tried the following:

``````const solve = (arrOne, arrTwo) => {
return arrOne.every(value => arrTwo.includes(value));
};
``````

It gives a correct result, but if you have `arrOne = [1, 2]` and `arrTwo = [1, 1, 2]`, it should fail according to the description of the problem.

The test cases for this exercise should be reformulated to include those border cases

a year ago

const solve = (arrOne, arrTwo) => { const newArr = arrOne.filter((one) => {
for(let i = 0; i < arrTwo.length; i++){ if(one === arrTwo[i]){ return one; } } }); return newArr.length === arrOne.length };

a year ago

` const solve = (arrOne, arrTwo) => { const a = arrOne.sort() const b = arrTwo.sort()

return JSON.stringify(a) === JSON.stringify(b) }; `

a year ago

``````const solve = (arrOne, arrTwo) => {
if ((!Array.isArray(arrOne)) || (!Array.isArray(arrTwo))) return 'Params must be arrays';
if (arrOne.length !== arrTwo.length) return false;
const hash1 = {};
const hash2 = {};

for (let val of arrOne) {
hash1[val] ? hash1[val]++ : hash1[val] = 1;
}

for (let val of arrTwo) {
hash2[val] = (hash2[val] || 0) + 1;
}

for (let key in hash1) {
if (!key in hash2) return false;
if (hash1[key] !== hash2[key]) return false;
}
return true;
};
``````

a year ago

``````const solve = (arrOne, arrTwo) => {
const hash = {};
for (let val of arrOne) {
hash[val] ? hash[val]++ : hash[val] = 1;
}
for (let val of arrTwo) {
if (!hash[val]) return false;
else hash[val] -= 1;
}
return true;
};

``````

a year ago

const solve = (arrOne, arrTwo) => { return arrOne.every((i)=>arrTwo.includes(i)) ; };

a year ago

``````const solve = (arrOne, arrTwo) => {
for(num of arrOne) {
if(arrTwo.indexOf(num) === -1) {
return false
}
}
return true;
};

``````

a year ago

``````const solve = (arrOne, arrTwo) => {
return arrOne.every(int => arrTwo.includes(int))
};

``````

a year ago

return (arrOne.length === arrTwo.length) && (arrOne.sort().every((v,i)=> v === arrTwo.sort()[i]))

a year ago

``````const solve = (arrOne, arrTwo) => {
if(arrOne.length !== arrTwo.length) return false

const compare = {}

for (const num of arrOne) {
compare[num] = true;
}

for (const num of arrTwo) {
if (!compare[num]) return false;
}

return true;
};
``````

2 years ago

A classic....

``````const solve = (arr1, arr2) => {
const asc = (a, b) => a - b
arr1.sort(asc);
arr2.sort(asc);
let flag = false;
arr1.forEach((i, n) => flag = i === arr2[n] ? true : false)
return flag
}
``````

2 years ago

``````const solve = (arrOne, arrTwo) => {
return arrOne.length === arrTwo.length ?  arrOne.every(v => arrTwo.includes(v)) : false
};

``````

2 years ago

const solve = (arrOne, arrTwo) => { return arrOne.length === arrTwo.length ? arrOne.every(v => arrTwo.includes(v)) : false };

2 years ago

below is the code copied from savings guy

const solve = (arrOne, arrTwo) => { const arrThr = arrOne.filter((pro) => { return arrTwo.includes(pro);}); return arrThr.length === arrOne.length; };

2 years ago

i copy the code of Mr Expert Savings Account Ergonomics in later exercise and applied here and it did work fine here. i think this code is more flexible and more comprehensive to be appied in all situations that come across like charaters as well

3 years ago

const solve = (arrOne, arrTwo) => { let result = []; const isEqual = () => { for(let i = 0; i<arrOne.length; i++){ if(arrOne[i] != arrTwo[i]){ result = false; } if(arrOne[i]==arrTwo[i]){ result = true; } } } return result; };

3 years ago

There is a mistake with the first solution. However, it seems working fine. Could you check the test cases?

3 years ago

const solve = (arrOne, arrTwo) => { return Array.from(arrOne).toString() === Array.from(arrTwo).reverse().toString(); };