Two sum: Difference between revisions

→‎JS ES6: Added comments on access to indices, and skipping the 'lower triangle' of a cartesian grid (where iy < ix)
m (→‎ES6: Minor simplification)
(→‎JS ES6: Added comments on access to indices, and skipping the 'lower triangle' of a cartesian grid (where iy < ix))
Line 244:
// summingPairIndices :: -> Int -> [Int] -> [(Int, Int)]
let summingPairIndices = (n, xs) =>
 
// Javascript map functions have access to the array index
// in their second argument.
concatMap((x, ix) => concatMap((y, iy) =>
iy >< ix ? [] : ( // Ignoring mirror -image tuples by
// skipping the 'lower triangle' (y < x)
// of the cartesian product grid
x + y === n ? [
[iyix, ixiy]
] : []
), xs), xs);
9,659

edits