Skip to content

Commit

Permalink
STAT-11: Manual testing mode code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereckmezquita committed Sep 6, 2024
1 parent d563385 commit 6b12ec1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dev/mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { mode } from '../src';
import { generateRandomNums } from '../benchmarks/utils';

const n: number = 100_000;
const random_nums: number[] = generateRandomNums(n);

function mode_simple(x: number[]): number {
const counts = new Map<number, number>();
for (const xi of x) {
counts.set(xi, (counts.get(xi) || 0) + 1);
}

let mode = NaN;
let maxCount = 0;
for (const [xi, count] of counts.entries()) {
if (count > maxCount) {
mode = xi;
maxCount = count;
}
}

return mode;
}

const mode_res1 = mode(random_nums);
const mode_res3 = mode_simple(random_nums);

console.log('mode_res1:', mode_res1);
console.log('mode_res3:', mode_res3);

0 comments on commit 6b12ec1

Please sign in to comment.