Skip to content

Instantly share code, notes, and snippets.

@thomasvaeth
Last active February 12, 2018 21:50
Show Gist options
  • Save thomasvaeth/33c679235be4eec7361f348642f6a989 to your computer and use it in GitHub Desktop.
Save thomasvaeth/33c679235be4eec7361f348642f6a989 to your computer and use it in GitHub Desktop.
"If you have a strong purpose in life, you don't have to be pushed. Your passion will drive you there." - Roy T. Bennett
// First Solution
function duplicate(arr, num) {
var newArr = [];
for (var i = 1; i <= num; i++) {
newArr = newArr.concat(arr);
}
return newArr;
}
// Second Solution
function duplicate(arr, num) {
var newArr = Array(num).fill(arr);
return newArr.reduce(function(a, b) {
return a.concat(b);
});
}
duplicate([1,2,3,4,5], 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment