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