UNPKG

@cromarmot/algo

Version:

Algorithms library with controllable time complexity.

30 lines (29 loc) 771 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isEvenRandom = exports.isEvenON = exports.isEven = void 0; function isEven(v) { return v % 2 == 0; } exports.isEven = isEven; // https://twitter.com/Tarrenam/status/1288749833143095298?s=20 function isEvenON(v) { let ret = true; while (v) { v -= 1; ret = !ret; } return ret; } exports.isEvenON = isEvenON; // https://twitter.com/cpuodzius/status/1288764516017348608?s=20 function isEvenRandom(v) { while (true) { if (2 * Math.round(Math.random() * v) == v) { return true; } else if (2 * Math.round(Math.random() * v) + 1 == v) { return false; } } } exports.isEvenRandom = isEvenRandom;