UNPKG

ds-algo-study

Version:

Just experimenting with publishing a package

28 lines (20 loc) 736 B
/*********************************************************************** Write a function `mirrorArray(array)` that takes in an array as an argument and returns a new array "mirrored" as shown in the examples: Examples: mirrorArray([1,2,3]); // => [ 1, 2, 3, 3, 2, 1 ] mirrorArray(['a', 'b', 'c', 'd']); // => [ 'a', 'b', 'c', 'd', 'd', 'c', 'b', 'a' ] ***********************************************************************/ const mirrorArray = (array) => { let newArray = []; for (let i = 0; i < array.length; i += 1) { let el = array[i]; newArray.push(el); } for (let i = array.length - 1; i >= 0; i -= 1) { let el = array[i]; newArray.push(el); } return newArray; }; module.exports = mirrorArray;