'learning about arrays, trying to implement postfix conversion to result
I have the following postfix to convert:
outputArray = [3,4,*,2,9,3,/,4,/,6]
Wanted result is slicedArray = [3, * , 4 ] so I can perform arithmetic operation.
This was my approach which did fail for some reason...
let outputArray = ['3','4','*','2','9','3','/','4','/','6']
outputArray.forEach((element) => {
while ((
element !== '*' ||
element !== '+' ||
element !== '-' ||
element !== '/' ||
element !== '^'
)) {
resultArray.push(outputArray.shift(element));
console.log("Hi Panda " + resultArray)
}
if (element.includes("+") ||
element.includes("-") ||
element.includes("*") ||
element.includes("/") ||
element.includes("^")) {
let panda = resultArray.length;
resultArray.splice(panda - 1, 0, element)
let slicedArray = resultArray.slice(-3)
console.log(slicedArray);
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
