Created
November 15, 2016 06:53
-
-
Save quangnd/694e0be3988c4b74a1669c4b57644a8d to your computer and use it in GitHub Desktop.
Array & utility functions
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
// 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