Skip to content

Instantly share code, notes, and snippets.

@Rabios
Last active June 11, 2021 21:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rabios/5f0d6ca722e61aa8c5371063581fc6a5 to your computer and use it in GitHub Desktop.
Save Rabios/5f0d6ca722e61aa8c5371063581fc6a5 to your computer and use it in GitHub Desktop.
Array consists of copies of other array's elements
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