jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
dfaf
function solution(N, number) {
let result = -1;
const n = 9;
const dpTable = Array.from({ length: n }, () => new Set());
for (let i = 1; i < n; i++) { // 1 2 3 4 5 6 7 8
dpTable[i].add('1'.repeat(i) * N); // Set(1) { 5 }, Set(1) { 55 } ...
for (let j = 1; j < i; j++) { // i = 2 j = 1, i = 3, j = 1, 2, i = 4 j = 1, 2, 3...
for (const arg1 of dpTable[j]) { // 5, 5, 55, 5, 55, 555...
for (const arg2 of dpTable[i - j]) {
// 5 + 5, 5 - 5, 5 * 5, 5 / 5
dpTable[i].add(arg1 + arg2);
dpTable[i].add(arg1 - arg2);
dpTable[i].add(arg1 * arg2);
dpTable[i].add(arg1 / arg2);
}
}
}
if (dpTable[i].has(number)) {
result = i;
break;
}
}
return result;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
solution(5, 12) |
| ready |
solution(2, 11) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.