Question #201238

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

Expert's answer

const arr1 = [ 12345 ];

const arr2 = [ 24 ];


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));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS