Last active
October 28, 2020 15:48
-
-
Save manzaloros/013fe9bb832dac7ae1cdabba34b0d0c3 to your computer and use it in GitHub Desktop.
summaryRanges.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const summaryRanges = (nums, [beginning, end] = [nums[0]]) => { | |
return nums.reduce((result, curr, i) => { | |
const next = nums[i + 1]; | |
if (curr + 1 !== (next)) { | |
result.push(end === beginning ? `${end}` : `${beginning}->${end}`); | |
beginning = next; | |
} | |
end = next; | |
return result; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment