I am trying to write a code(function) that takes in two parameters a and b, and returns all the even number between a and b if a is greater than b else it should return the odd numbers between a and b.
this is my code.
function number_ranges (a, b) {
let numbers = [];
if (a > b){
for (let i = b; i < a; i++){
if (i > b){
numbers.push(i);
}
}
}else{
for (let i = a; i < b; i++){
if (i > a){
numbers.push(i);
}
}
}
const result = numbers.filter(function(num){
return a > b ? num % 2 === 0: num % 2 === 1;
});
return result;
}
I would like to see a different approach because i cant seem to be able to pass all the test cases
if(i > a)so why not just start it ati=a+1and not have to do that check?