Are they the “same”? CodeWars

后端 未结 1 1443
清歌不尽
清歌不尽 2021-01-29 03:01

HERE IS THE FULL QUESTION DESCRIPTION

Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two array

相关标签:
1条回答
  • 2021-01-29 03:34

    The easiest possible way:

    const comp = (a1, a2) => {
      if (!a1 || !a2 || a1.length !== a2.length) return false;
      return a1.map(x => x * x).sort().toString() === a2.sort().toString();
    }
    
    0 讨论(0)
提交回复
热议问题