Created
December 20, 2014 20:44
-
-
Save SeeThruHead/906a19ba4d0d87604d58 to your computer and use it in GitHub Desktop.
Fill an array with another array, repeating when necessary.
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
// Init a source array contains numbers 0-35 | |
var source = Array.apply(null, {length: 36}).map(Number.call, Number); | |
// Init the result array as undefined using the arguments pseudo array. | |
var result = Array.apply(null, {length: 100}); | |
// The magic | |
result = result.map(function(val, index) { | |
return source[index % source.length]; | |
}); | |
console.log(result.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment