Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,26 @@
const e = '3 4 2 * 1 5 - 2 3 ^ ^ / +';
const s = [], tokens = e.split(' ');
for (const t of tokens) {
const n = Number(t);
if (!isNaN(n)) {
s.push(n);
} else {
if (s.length < 2) {
throw new Error(`${t}: ${s}: insufficient operands.`);
}
const o2 = s.pop(), o1 = s.pop();
switch (t) {
case '+': s.push(o1 + o2); break;
case '-': s.push(o1 - o2); break;
case '*': s.push(o1 * o2); break;
case '/': s.push(o1 / o2); break;
case '^': s.push(Math.pow(o1, o2)); break;
default: throw new Error(`Unrecognized operator: [${t}]`);
}
}
console.log(`${t}: ${s}`);
}
if (s.length > 1) {
throw new Error(`${s}: insufficient operators.`);
}