Last active
June 16, 2017 03:45
-
-
Save Daniel-Hug/d2b8ee2ad3049061f5970bfe77603781 to your computer and use it in GitHub Desktop.
JS function: trim undefined values from ends of array
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
function trimArray(arr) { | |
for (var start = 0; start < arr.length && !(start in arr); start++); | |
for (var end = arr.length; end > start && !(end - 1 in arr); end--); | |
return arr.slice(start, end); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment