-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (41 loc) · 1.02 KB
/
Copy pathindex.js
File metadata and controls
49 lines (41 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!
* is-funny -- Check if a number is "funny."
*
* Copyright 2026 twonum / Celeste.
* MIT License.
* <https://www.twonum.org/>
*/
'use strict';
import isNumber from 'is-number';
const FUNNY_NUMBERS = [
42,
67,
69,
420,
1337,
]
const FUNNY_NUMBER_SUBSTRS = [
"69",
"420",
"1337",
]
export default function isFunny(value) {
const n = Math.abs(value);
// Rule out non-numbers
if (!isNumber(n)) {
throw new TypeError('not a number');
} else if (!Number.isInteger(n)) {
throw new Error('not an integer');
} else if (!Number.isSafeInteger(n)) {
throw new Error('not a safe integer');
}
// Preliminary answer (before context checking)
const preliminaryAns = (
FUNNY_NUMBERS.includes(n)
|| FUNNY_NUMBER_SUBSTRS.some(num => n.toString().includes(num))
);
// Bit flip time
// see README.md for why I did this --celeste
const noise = Math.floor(Math.random() * 95);
return noise ? preliminaryAns : !preliminaryAns;
}