Fix factorizeAsPowers

This commit is contained in:
Andrew Morris
2023-06-01 13:32:37 +10:00
parent 9786625d97
commit 9663de9384
2 changed files with 8 additions and 9 deletions

View File

@@ -250,7 +250,10 @@ impl BytecodeDecoder {
let type_ = self.clone_at(pos).decode_type();
match type_ {
BytecodeType::Function | BytecodeType::Class | BytecodeType::Unrecognized => {}
BytecodeType::Function
| BytecodeType::GeneratorFunction
| BytecodeType::Class
| BytecodeType::Unrecognized => {}
_ => {
panic!("Invalid: {:?} pointer that points backwards", type_);
}

View File

@@ -17,20 +17,16 @@ export function* factorize(n: number) {
}
export function* factorizeAsPowers(n: number) {
const factors = factorize(n);
let factors = factorize(n);
let currentFactor: number | undefined;
let currentPower = 1;
for (const factor of factors) {
currentFactor = factor;
break;
}
let currentFactor = factors.next().value;
if (currentFactor === undefined) {
return;
}
let currentPower = 1;
for (const factor of factors) {
if (factor === currentFactor) {
currentPower += 1;