DEV Community

Discussion on: Daily Challenge #215 - Difference of 2

Collapse
 
savagepixie profile image
SavagePixie

Something like this should do it in JavaScript. I'm not entirely sure if this sort is okay, though. I can never remember which way it's ascendent and which descendent.

const pairDifference = list => list
    .sort()
    .filter(x => list.includes(x + 2))
    .map(x => [ x, x + 2 ])
Enter fullscreen mode Exit fullscreen mode
Collapse
 
monfernape profile image
Usman Khalil

This really is Savage