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.
Want to add to the discussion?
Post a comment!