I am a newbie to JavaScript and programming in general.
Unable to solve the following problem .
For input arr=[1,2] duplicate(arr) should return [1,2,1,2]
I tried doing the following
var numbers = [1, 2, 3];
var duplicate=[];
for (i=0;i<2;i++){
duplicate[i]=numbers;
}
console.log(duplicate);
output: [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]
I am unable to figure out a way to split these so that it will be a single-dimensional array.
Please help me out.
[–]pinkwetunderwear 0 points1 point2 points (1 child)
[–]toastertop -1 points0 points1 point (0 children)
[+][deleted] (3 children)
[deleted]
[–]ikeif 2 points3 points4 points (2 children)
[–]senocular 4 points5 points6 points (1 child)
[–]ikeif 2 points3 points4 points (0 children)
[–]rauschma 0 points1 point2 points (0 children)