Comments

Gorgeous Cotton2 months ago

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

Hajk Dallakjan3 months ago

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

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

};`

Matías Duhalde5 months 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

Mac Villegas8 months 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 Baez8 months ago

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

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

Bryan Guilas8 months 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;
};

Bryan Guilas8 months 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;
};

Fatih KAYA9 months ago

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

Richard O'Brien9 months ago

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


Sergey Riedel10 months ago

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

Home 1080p invoicea year ago

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 Tugrika year 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
}

Abdelhamid Ismail2 years ago

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

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

SAS2 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 Tezcan2 years ago

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

Mertkan Tezcan2 years ago

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