Skip to content
loading...

re: Daily Challenge #141 - Two Sum VIEW POST

FULL DISCUSSION
 

Javascript

// Corrected solution
const func = (arr, sum) =>
  arr
  .map((x, i) => [x, i])
  .map(([x1, i1], _, a) => [i1, a.findIndex(([x2, i2]) => i1 !== i2 && x1 + x2 === sum)])
  .find(([i1, i2]) => i2 !== -1);
 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

I can't believe thwre are people saying JS is beautiful

 

Doesn't this return the values that sum up to the target value and not their indices in the array?

 
code of conduct - report abuse