-
Notifications
You must be signed in to change notification settings - Fork 487
/
is.js
153 lines (146 loc) · 4.25 KB
/
is.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var noop = require('noop3');
var consts = require('./consts');
const THIRTEEN = consts.THIRTEEN;
const THIRTEEN_FUZZ = consts.THIRTEEN_FUZZ;
const thirteenStrings = consts.thirteenStrings;
'use strict';
/**
* @param n {number} The number to compare but also sometimes not a number but not not !NaN
* @returns {object}
*/
var is = function is(x) {
// the next line calls the noop function
noop();
// Every element should be lower case
if (thirteenStrings.indexOf(('' + x).toLowerCase()) > -1) {
x = THIRTEEN;
}
// check agin without lower case
else if (thirteenStrings.indexOf(('' + x)) > -1) {
x = THIRTEEN;
}
else if( (typeof x) === "string" && /^[Il1]{13,13}$/.test(x) ) {
x = THIRTEEN;
}
else if (typeof x === 'string') {
var chars = (x).split('');
if (chars.length == THIRTEEN && chars.every(function(e) { return e === chars[0]})) {
x = THIRTEEN;
}
else if (chars.length == 26 && '\ud800' <= chars[0] && chars[0] <= '\udbff'
&& '\udc00' <= chars[1] && chars[1] <= '\udfff'
&& chars.every(function(e, idx) { return e === chars[idx % 2]})) {
x = THIRTEEN;
}
}
return {
thirteen: function() {
return x == THIRTEEN;
},
roughly: {
thirteen: function() {
for (var i = 0, len = thirteenStrings.length; i < len; i++) {
if (('' + x).toLowerCase().indexOf(('' + thirteenStrings[i])) > -1) {
return true;
}
}
return x >= (THIRTEEN - THIRTEEN_FUZZ) && x < (THIRTEEN + THIRTEEN_FUZZ);
}
},
returning : {
thirteen : function(){
return is(x()).thirteen();
}
},
not: {
thirteen: function() {
return !is(x).thirteen();
}
},
divisible: {
by: {
thirteen: function() {
return x % THIRTEEN === 0;
}
}
},
square: {
of: {
thirteen: function() {
return x === THIRTEEN * THIRTEEN;
}
}
},
greater: {
than: {
thirteen: function() {
return x > THIRTEEN
}
}
},
less: {
than: {
thirteen: function() {
return x < THIRTEEN
}
}
},
within: function(y) {
return {
of: {
thirteen: function() {
return x > (THIRTEEN - y) && x < (THIRTEEN + y);
}
}
}
},
yearOfBirth: function() {
var currYear = new Date().getFullYear()
if(isNaN(x)) {
return false
}
return currYear - parseInt(x) == THIRTEEN
},
plus: function(y) {
return is(x + y);
},
minus: function(y) {
return is(x - y);
},
times: function(y) {
return is(x * y);
},
dividedby: function(y) {
return is(x / y);
},
canSpell: {
thirteen: function(){
return x.toLowerCase().includes("t","h","i","r","t","e","e","n");
}
},
anagramOf:{
thirteen:function(){
return x.toLowerCase().split('').sort().join('').trim() == "thirteen".split('').sort().join('').trim();
}
},
backwards: {
thirteen: function() {
return parseInt(x.toString().split("").reverse().join("")) == THIRTEEN;
}
},
atomicNumber: {
thirteen: function() {
return x.toLowerCase().includes("a","l","u","m","i","n","u","m");
}
},
base: function(y) {
return {
thirteen: function() {
var basedNumber = parseInt(x, y);
return !isNaN(basedNumber) && basedNumber == THIRTEEN;
}
}
}
}
};
module.exports = is;