Challenge 2: Return an Array of Squares
This challenge tests your knowledge of functions and arrays.
We'll cover the following
Problem Statement
The task is to modify the given function arr_square()
to use loops to iterate over an array, which is declared within the function, and replace all of its elements by their squares.
Test Sample
An array of integers declared in the funtion:
[1, 2, 3, 4, 5]
Output
The function should return the following array:
[1, 4, 9, 16, 25]
Coding Exercise
Write your code below. It is recommended​ that you try solving the exercise yourself before viewing the solution.
Note: There is an
arr_square
function given in the code for testing purposes. Do not modify it.
Good luck! 🤞
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy