mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Fix factorizeAsPowers
This commit is contained in:
@@ -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_);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user