Typescript change position of arrays elements (odd with even)

This is the extract of my scenario. I have an array with coordinates, let me do the example with integer numbers.

const myArray = [1,2,3,4,5,6,7,8];

And the output array I expect is:

finalArray = [2,1,4,3,6,5,8,7];

I just want to change the even and odds position, but not to invert the array.

Can someone explain to me how to do it?

I'm trying to do it with a map, but still no luck



from Recent Questions - Stack Overflow https://ift.tt/2Jep9XU
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation