Arrays
Algorithms
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,[])    
    }
  • 11
    // slightly better performance, although still not great
    
    22
    function pair(arr) {
    
    3
      for (var a of arr)
    
    4
        if (a < 0 && arr.includes(-a))
    
    5
          return [a, -a]
    
    3+
     return arr.reduce((acc,no) => no < 0 && arr.includes(-no) ? acc.concat([no, -no]) : acc,[])    
    
    66
    }