Answer to Question #201238 in HTML/JavaScript Web Application for Hari nadh babu

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

1
Expert's answer
2021-06-01T00:01:10-0400
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));

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!

Comments

Assignment Expert
01.06.21, 10:10

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!



Hari nadh babu
01.06.21, 07:37

Awesome! Thank you.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS