Q:

Even Position Element

I am having difficulties solving the following math problem: 
'Write a JS function that finds the elements at even positions in an array.
The input comes as an array of number elements.
The output must be displayed into element with id result like a text/string.'
Input : [1, 2, 3, 4, 5, 6, 7, 8, 9] 
Output: 1 x 3 x 5 x 7 x 9 
This is my code until now:
function evenPosition(arr) {

    let evenIndexes = [];
    let oddIndexes = [];

    for (let i = 1; i < arr.length + 1; i++) { 

        if (i % 2 !== 0) {
            oddIndexes.push(i)
        } else {
            evenIndexes.push(i)
        }

    }

}
evenPosition([1, 2, 3, 4, 5, 6, 7, 8, 9])

I cannot sort the elements though as it is shown in the output... Can you guys please help?

A:

You can use array's join method to convert array into string with the  character's you want to join. Something like this.
function evenPosition(arr) {

    let evenArr = [];
    for (let i = 0; i < arr.length; i++) { 

        if (i % 2 === 0) { 
            evenArr.push(arr[i]);
        }

    }
    return evenArr.join(" x ");
}
console.log(evenPosition([1, 2, 3, 4, 5, 6, 7, 8, 9]))

If you want to sort the array also then you can return something like this.
return evenArr.sort().join(" x ");

