main.js
1
2
3
4
5
6
7
8
9
10
11
12
function append(array, toAppend) {
  const arrayCopy = array.slice();
  if ('first' in toAppend) {
    arrayCopy.unshift(toAppend.first);
  }
  if ('last' in toAppend) {
    arrayCopy.push(toAppend.last);
  }
  return arrayCopy;
}
console.log(append([2, 3, 4], { first: 1, last: 5 })); // => [1, 2, 3, 4, 5]
console.log(append([10], { first: 0, last: false }));  // => [0, 10, false]
Native Browser JavaScript