Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

902 B

title
title
Add Elements to the End of an Array Using concat Instead of push

Add Elements to the End of an Array Using concat Instead of push


Problem Explanation

Where the push method adds new element to the end of the orginal array, the concat method creates a new array containing the elements from the original array and the new element. The original array remains the same when using concat.


Solutions

Solution 1 (Click to Show/Hide)
function nonMutatingPush(original, newItem) {
  // Add your code below this line

  return original.concat(newItem);

  // Add your code above this line
}

var first = [1, 2, 3];
var second = [4, 5];
nonMutatingPush(first, second);