Square at Alternate Indices
Write a Javascript Program for Square at Alternate Indices
The below link contains Square at Alternate Indices Question and Test cases
https://drive.google.com/file/d/1NMtBGioe4_oPKJpvPJ3iQW_7uRd2zjWz/view?usp=sharing
The below link contains code
https://drive.google.com/file/d/1mqvV-SoTKa6m2tUL_rxcBeWcdKjUVZgm/view?usp=sharing
In this Javascript coding program they had two test cases
We need all two test cases can be came when code was run. I want exact outputs for all two test cases
const arr1 = [ 1, 2, 3, 4, 5 ];
const arr2 = [ 2, 4 ];
function squareAlternate(arr) {
return arr.map( (item, index) => {
if (index % 2 == 0) {
return item *= item;
} else return item;
})
}
console.log(squareAlternate(arr1));
console.log(squareAlternate(arr2));
Comments
Dear Hari nadh babu,
You're welcome. We are glad to be helpful.
If you liked our service please press like-button beside answer field. Thank you!
Awesome! Thank you.
Leave a comment