Skip to content

Commit

Permalink
Squash variable leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 22, 2024
1 parent ac72a1c commit 6f4531b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions javascript/src/lib/factors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* @yield {number}
*/
function* properDivisors(num) {
factors = [...primes.primeFactors(num)];
const factors = [...primes.primeFactors(num)];
const seen = new Set();
yield 1;
for (let x = 1; x < factors.length; x++) {
for (const combo of iters.combinations(factors, x)) {
ret = combo.reduce((a, x) => a * x, 1);
const ret = combo.reduce((a, x) => a * x, 1);
if (!seen.has(ret)) {
yield ret;
seen.add(ret);
Expand Down
4 changes: 2 additions & 2 deletions javascript/src/lib/iters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports.combinations = function* combinations(iterable, r) {
if (r > n) {
return;
}
indices = [...Array(r).keys()];
const indices = [...Array(r).keys()];

yield Array.from(indices.map((i) => pool[i]));
while (true) {
Expand Down Expand Up @@ -49,7 +49,7 @@ exports.combinationsWithReplacement = function* combinationsWithReplacement(iter
if (r > n) {
return;
}
indices = [...Array(r).keys()];
const indices = [...Array(r).keys()];

yield Array.from(indices.map((i) => pool[i]));
while (true) {
Expand Down
4 changes: 2 additions & 2 deletions javascript/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ exports.get_answer = function(n) {
continue;
}
if (type === 'str') {
if (value.length !== parseInt(size)) {
if (value.length !== Number(size)) {
throw new Error('string length does not match');
}
return value;
}
return parseInt(value);
return Number(value);
}
throw new Error('Answer not found');
};

0 comments on commit 6f4531b

Please sign in to comment.