Creates new array, and then set value to all indexes betweeb startIndex and endIndex. Then return result