const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];
let arrLength = valid1.length - 1;
let emptyarr = [];
let doubleNumber = [];
let minusNine = [];
let notAffected = [];
for (let i = arrLength; i >= 0; i--) {
while (i < arrLength && i >= 0) {
doubleNumber = valid1[i] * 2;
emptyarr.push(valid1[i] * 2);
i--;
}
newArr = emptyarr;
}
console.log(newArr);
console.log("NewArr is an array: " + Array.isArray(newArr));
console.log("*************************************")
let arrLength2 = newArr.length;
for (let j = 0; j < newArr.length; j = j + 1) {
while (j < arrLength2 && j >= 0) {
if (newArr[j] > 9) {
minusNine = newArr[j] - 9;
console.log(minusNine);
} else if (newArr[j] < 9 && newArr[j] >= 0) {
notAffected = newArr[j] * 1;
console.log(notAffected);
}
j++
}
}
console.log("*************************************")
Hello I am stuck with this code. What I am planning to do is taking the array, newArr, and check every element that this array has, if there´s a number greater than 9 the code will substract 9 to that element otherwise it will not affect the elements, in other words the numbers that are less than nine will remain invariable.
after doing the if and else if statements , I got the results that I expect however these numbers must be in a new array but when I try to place these numbers into a single array I get null results.
I appreciate your guidance
best wishes