Last active
October 5, 2018 08:21
-
-
Save L00Cyph3r/e794c01c2aafa7680a31e7fc4d414a49 to your computer and use it in GitHub Desktop.
Revisions
-
L00Cyph3r revised this gist
Oct 5, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,9 @@ function rangeToString(items) { var range = false; var string = ''; for (var i = 0; i < items.length; i++) { if (point === items[i]) { continue; } if (point === null) { string = string + items[i]; } else if ((point + 1) === items[i]) { -
L00Cyph3r created this gist
Oct 5, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ /** * Originally from: https://stackoverflow.com/a/24104156 * Rewritten in JavaScript */ var pagenumbers = [ 10,12,13,45,46,47,48,49,50,3,4,5 ]; function rangeToString(items) { items.sort(function (a, b) { return a - b; }); var point = null; var range = false; var string = ''; for (var i = 0; i < items.length; i++) { if (point === null) { string = string + items[i]; } else if ((point + 1) === items[i]) { range = true; } else { if (range === true) { string = string + '-' + point; } string = string + ',' + items[i]; } point = items[i]; } if (range === true) { string = string + '-' + point; } return string; } var string = rangeToString(pagenumbers);