0





7

Advertisement

I can not test the return value of my function correctly at the time of return.

My exercise is this: I must compare two arrays and return true if they have at least one identical element but I need some assistance in figuring out what is wrong with my code:

function duplicateElements(m, n){
  function test (element){
    return n.includes(element);
  }
  return m.filter(test) != [] ? true:false;
}
Question author Nedjim-dn | Source

Advertisement


0


Tu dois tester la propriété length de la valeur de retour.
--
You have to test the length property of the return value.

function duplicateElements(m, n) {
    function test(element) {
        return n.includes(element);
    }

    return m.filter(test).length > 0 ? true : false;
}
Answer author Andreas