-
-
Save whoeverest/ca4d8285257e98145952 to your computer and use it in GitHub Desktop.
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
/** | |
* Creates an array in which the contents of the given array are interspersed | |
* with... something. If that something is a function, it will be called on each | |
* insertion. | |
*/ | |
function intersperse(array, something) { | |
if (array.length < 2) { | |
return array; | |
} | |
var result = []; | |
for (var i = 0; i < array.length - 1; i++) { | |
result.push(array[i], something); | |
} | |
result.push(array[i]); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment