- Add a value to the middle of your array without the stock method
- Write a function called insertShiftArray which takes in an array and the value to be added. Without utilizing any of the built-in methods available to your language, return an array with the new value added at the middle index.
- Approach
- Count the elements in the array
- Divide by 2 and round up if the total was odd
- Iterate over the array, assigning them to the new array around the middle empty index
- Assign the given value to the empty middle empty index
- Return the array
- Test with
node
andconsole.log
, then unit tests
- Big 0
- Small and short