Last active
June 11, 2021 21:51
-
-
Save Rabios/5f0d6ca722e61aa8c5371063581fc6a5 to your computer and use it in GitHub Desktop.
Array consists of copies of other array's elements
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
function copy_array(a, t) { | |
var result = []; | |
if (t == 0 || t == 1) { | |
result = a; | |
} else { | |
for (var i = 0; i <= t - 1; i++) { | |
for (var j = 0; j < a.length; j++) result.push(a[j]); | |
} | |
} | |
return result; | |
} | |
var arr = copy_array([1, 0], 4); // [1, 0] ==> [1, 0, 1, 0, 1, 0, 1, 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment