a guest Oct 12th, 2015 1,595 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- const nextId = ids => ids
- .sort((x, n) => x >= n ? 1 : -1)
- .reduce((acc, n, i, a) => acc !== null ? acc : (i === 0 && n > 0) ? 0 : ((typeof a[i+1] !== 'undefined') ? ((a[i+1] !== n && a[i+1]-1 !== n) ? n+1 : null) : n+1) , null)
RAW Paste Data