CC-09: Array Mutations
Code Challenge
const replaceWithYerr = (arr, start, num) => {
let res = [...arr];
for (; num > 0; num--) {
res[start++] = "yerr";
}
return res;
}
// const months = ['Jan', 'February', 'March', 'April', 'May', 'June'];
// console.log(`test case:`);
// console.log(replaceWithYerr(months, 1, 3)) //['Jan', 'yerr', 'yerr, 'yerr', 'May', 'June']k
// console.log(`checking original arr:`);
// console.log(months);const replaceWithYerr2 = (arr, start=0, num=arr.length) => {
let res = [...arr];
for (; num > 0; num--) {
res[start++] = "yerr";
}
return res;
}
// const months2 = ['Jan', 'February', 'March', 'April', 'May', 'June'];
// console.log(`first case:`);
// console.log(replaceWithYerr2(months2, 1)) //['Jan', 'yerr', 'yerr, 'yerr', 'yerr', 'yerr']
// console.log('second case:');
// console.log(replaceWithYerr2(months2)) //['yerr', 'yerr', 'yerr, 'yerr', 'yerr', 'yerr']
// console.log(`checking original array:`);
// console.log(months);Last updated