Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Challenge Summary

Insert and shift an array in middle at index

Challenge Description

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 & Efficiency

My approach was to calculate the middle index of the given array using array.length, the iterate backwards through the array to that point. At each index, move the value currently stored at the index to one slot over (index + 1), effectively lengthening the second half of the array by a single index value.

When the middle index is reached, set that value to the given insertion value.

Solution

arrayWhiteboard