110k views
14 votes
Write a method named split that accepts an array of integers as a parameter and returns a new array twice as large as the original, replacing every integer from the original array with a pair of integers, each half the original.

User GregC
by
6.1k points

1 Answer

5 votes

Answer:

Step-by-step explanation:

The following code is written in Python. It creates a function that is called split and takes an array of integers as a parameter. Then it loops through that array and divides the current element by 2 and saves it in a variable called half. Then it adds half two times into a new array called new_array. Finally, once the loop is over it returns the new_array.

def split(my_array):

new_array = []

for x in my_array:

half = x / 2

new_array.append(half)

new_array.append(half)

return new_array

User Jaredzhang
by
5.3k points