Ad
Arrays
Data Types
Algorithms
Logic
Data
Code
Diff
  • // slightly better performance, although still not great
    function pair(arr) {
     return arr.reduce((acc,no) => no < 0 && arr.includes(-no) ? acc.concat([no, -no]) : acc,[])    
    }
    • // slightly better performance, although still not great
    • function pair(arr) {
    • for (var a of arr)
    • if (a < 0 && arr.includes(-a))
    • return [a, -a]
    • return arr.reduce((acc,no) => no < 0 && arr.includes(-no) ? acc.concat([no, -no]) : acc,[])
    • }