CC-09: Array Mutations
with Carmen Salas • 2024/10/17
Code Challenge
Declare a function named
replaceWithYerr
that accepts three arguments: an Array, a start index, and the number of elements to replace with the string 'yerr'. The function should return a new Array, with the same elements as the original Array, except elements at the starting index, are replaced with the string 'yerr'. The number of elements replaced is determined by the third argument. Implement this function without using.splice()
.
Bonus: Refactor your function so that the second and third arguments are optional. If the third argument is missing, the function should return a new array that replaces all elements from the starting index to the end of the array. If only an one argument is passed, it should return a new array argument, with all elements replaced that is the same length as the input array.
Last updated