1 - first create an array with all numbers between n and p.
2- create a second array to collect all odd numbers using For loop.
In For loop, collect all odd numbers using Math.floor() method. Any odd number divided by 2 will not be equal to the nearest integer created by Math.floor() and thus, that number will be included in the second array. All the even numbers will be filtered out as that even number divided 2 and Math.floor() integer divided by 2 will be of same value.
Code:
function numbers(n, p) {
let allArr = [];
for (let i = n; i <= p; i++) {
allArr.push(i);
}
let result = [];
for (let j = 0; j < allArr.length; j++) {
if (allArr[j] / 2 !== Math.floor(allArr[j] / 2)) {
result.push(allArr[j]);
}
}
return result;
}
console.log(numbers(10, 19));
2toi..?2n + 1wherenis a member of the integers