Skip to content

Instantly share code, notes, and snippets.

let xn = (x, n) => x ** (n - 1n); // TODO: has a probably O(n!) complexity. More efficient algorithm needed.
function mod(x, n) {
const _xn = xn(x, n);
return (_xn - 1n) % n === 0n;
}
function withTimer(fn, timeName = 'Run time') {
return (...args) => {
console.time(timeName);
@xkizer
xkizer / test.js
Last active December 4, 2017 09:37
function test() {
assert.shouldEqual(factorial(0), 1);
assert.shouldEqual(factorial(1), 1);
assert.shouldEqual(factorial(2), 2);
assert.shouldEqual(factorial(6), 1);
assert.shouldEqual(factorial(10), 3628800);
assert.shouldEqual(factorial(12), 479001600);
assert.shouldEqual(factorial(18), 6402373705728000);
// Throw error for factorials greater than 18
'use strict';
/**
* Flattens a deep-nested array of integers (numbers)
* @param {Number[]} inpArray A possibly deep-nested array of numbers.
* The level of nesting is limited by the maximum stack size of the
* JavaScript engine (the lowest we have seen is IE6 at 1130)
* @return {Number[]} Returns a flattened version of the input array
*/
function flatten (inpArray) {
@xkizer
xkizer / nextTick.js
Created May 28, 2012 21:28 — forked from mmalecki/nextTick.js
process.nextTick vs setTimeout(fn, 0)
for (var i = 0; i < 1024 * 1024; i++) {
process.nextTick(function () { Math.sqrt(i) } )
}