The problem I have to solve is the following -
splitEven(a) – The function accepts an array of integers and would return an
array that contains the values that are located in the even indices of the original
array, sorted in ascending order.
For example, if the function gets the array [3, 1, 6, 7, 4] it would return the array
[3, 4, 6]
This is my solution -
function splitEven(a){
var b = [];
var even = function(element){
return element % 2 === 0;
}
for (var i = 0; i < a.length; i++) {
var c = even(a[i]);
if (c) {
b.push(a[i])
}
}
return b;
}
However I feel it is not best practice to do what I have done. I am familier with Java, and I think I tend to solve problems not in the right way.
Can you think of a better approach for this problem, to improve my practice?