Skip to content

Instantly share code, notes, and snippets.

@SeeThruHead
Created December 20, 2014 20:44
Show Gist options
  • Save SeeThruHead/906a19ba4d0d87604d58 to your computer and use it in GitHub Desktop.
Save SeeThruHead/906a19ba4d0d87604d58 to your computer and use it in GitHub Desktop.
Fill an array with another array, repeating when necessary.
// 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