Skip to main content
3 of 5
added 27 characters in body
James
  • 567
  • 2
  • 8

No, each number requires a second pass to determine whether combined with an existing one it is a match - doesn't mean it can't be short though e.g.

const checkIfSumFromTwoNumbers = (arrayOfNums, targetValue) => 
  arrayOfNums.reduce((matches, val) => {
      const target = arrayOfNums.find(x => (val + x) === targetValue);
      target && matches.push([val, target]);
      return matches;
   }, [])
James
  • 567
  • 2
  • 8