Create a function that accepts an array and returns a new, with duplicate elements, input array. I have such code, but there is an error in it, as correct

function map(Array) { let napp = []; for (let i = 0; i<Array.length; i++){ } return napp; } let doubleArray = Array.concat([1, 2, 3]); console.log(doubleArray); 

?

  • I'm afraid to even ask what the error in your code is from your point of view. What order of elements do you need in the resulting array? 1,2,3 => 1,2,3,1,2,3 or 1,2,3,3,2,1 or 1,2,3,1,2,3 or 1,2,3,3,2,1 else? - teran
  • It is necessary that you can add any number, but the example shows how: 1,2,3,1,2,3 - Matc

2 answers 2

 function dblArr(a){ return a.concat(a); } var a = [1,2,3]; console.log( dblArr(a) ); 

     function map(arr) { let napp = []; for (let i = 0; i<arr.length; i++){ napp.push(arr[i]); } return napp; } var arr = map([1,2,3]); let doubleArray = arr.concat(arr); console.log(doubleArray); 

    • can you say how the map function is used here in general, the code of which you added? - teran
    • I did not understand the question correctly, sorry. Fixed :) - Puvvl