Skip to content

Instantly share code, notes, and snippets.

@quangnd
Created November 15, 2016 06:53
Show Gist options
  • Save quangnd/694e0be3988c4b74a1669c4b57644a8d to your computer and use it in GitHub Desktop.
Save quangnd/694e0be3988c4b74a1669c4b57644a8d to your computer and use it in GitHub Desktop.
Array & utility functions
// Flat 2D array to 1D arry
var arr=[[1,2],[3,4],[5,6]];
var result=[].concat(...arr);
console.log(result); //output: [ 1, 2, 3, 4, 5, 6 ]
// ------------------------
// Produce a specified number of repeating characters:
function repeat(s,n){
return [...Array(n+1)].join(s);
}
console.log(repeat("a",5)); //output: aaaaa
console.log(repeat("abc",5)); //output: abcabcabcabcabc
// ------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment