return (arrOne.length === arrTwo.length) && (arrOne.sort().every((v,i)=> v === arrTwo.sort()[i]))
Nathan Hanniga 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;
};
Ameliorated Tugrik2 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
}
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
SAS3 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;
};
Mertkan Tezcan3 years ago
There is a mistake with the first solution.
However, it seems working fine. Could you check the test cases?
Comments
Lenry Kabu7 months ago
Gorgeous Cotton9 months ago
Hajk Dallakjan10 months ago
`const solve = (arrOne, arrTwo) => {
return arrOne.sort().join("") === arrTwo.sort().join("") ? true : false
};`
MatÃas Duhaldea year ago
I naively tried the following:
It gives a correct result, but if you have
arrOne = [1, 2]
andarrTwo = [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
Mac Villegasa 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 };
Alejandro Baeza year ago
` const solve = (arrOne, arrTwo) => { const a = arrOne.sort() const b = arrTwo.sort()
return JSON.stringify(a) === JSON.stringify(b) }; `
Bryan Guilasa year ago
Bryan Guilasa year ago
Fatih KAYAa year ago
const solve = (arrOne, arrTwo) => { return arrOne.every((i)=>arrTwo.includes(i)) ; };
Richard O'Briena year ago
Sergey Riedela year ago
Home 1080p invoicea year ago
return (arrOne.length === arrTwo.length) && (arrOne.sort().every((v,i)=> v === arrTwo.sort()[i]))
Nathan Hanniga year ago
Ameliorated Tugrik2 years ago
A classic....
Abdelhamid Ismail2 years ago
Abdelhamid Ismail2 years ago
const solve = (arrOne, arrTwo) => { return arrOne.length === arrTwo.length ? arrOne.every(v => arrTwo.includes(v)) : false };
zunair jarral2 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; };
zunair jarral2 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
SAS3 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; };
Mertkan Tezcan3 years ago
There is a mistake with the first solution. However, it seems working fine. Could you check the test cases?
Mertkan Tezcan3 years ago
const solve = (arrOne, arrTwo) => { return Array.from(arrOne).toString() === Array.from(arrTwo).reverse().toString(); };