Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f35bfbf

Browse files
Fixed some jslint errors
1 parent 9fdbdc2 commit f35bfbf

File tree

1 file changed

+51
-29
lines changed

1 file changed

+51
-29
lines changed

‎biginteger.js‎

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*jslint newcap: true, eqeqeq: true, undef: true */
2+
/*global */
13
/*
24
JavaScript BigInteger library version 0.9
35
http://silentmatt.com/biginteger/
@@ -31,7 +33,9 @@
3133
if (!Array.prototype.map) {
3234
Array.prototype.map = function(fun /*, thisp*/) {
3335
var len = this.length >>> 0;
34-
if (typeof fun != "function") throw new TypeError();
36+
if (typeof fun !== "function") {
37+
throw new TypeError();
38+
}
3539

3640
var res = new Array(len);
3741
var thisp = arguments[1];
@@ -99,7 +103,7 @@ function BigInteger(n, s) {
99103

100104
// Keep editor from complaining about not returning
101105
return undefined;
102-
};
106+
}
103107

104108
// Constant: ZERO
105109
// <BigInteger> 0.
@@ -191,14 +195,14 @@ BigInteger.digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
191195
The string representation of the <BigInteger>.
192196
*/
193197
BigInteger.prototype.toString = function(base) {
194-
base = base || 10;
198+
base = +base || 10;
195199
if (base < 2 || base > 36) {
196200
throw new Error("illegal radix " + base + ".");
197201
}
198202
if (this._s === 0) {
199203
return "0";
200204
}
201-
if (base == 10) {
205+
if (base === 10) {
202206
// [].reverse() modifies the array, so we need to copy if first
203207
return (this._s < 0 ? "-" : "") + (this._d.slice().reverse().join("") || "0");
204208
}
@@ -261,7 +265,7 @@ BigInteger.radixRegex = [
261265
/^[0-9a-wA-W]*$/,
262266
/^[0-9a-xA-X]*$/,
263267
/^[0-9a-yA-Y]*$/,
264-
/^[0-9a-zA-Z]*$/,
268+
/^[0-9a-zA-Z]*$/
265269
];
266270

267271
/*
@@ -304,22 +308,24 @@ BigInteger.parse = function(s, base) {
304308
function expandExponential(str) {
305309
str = str.replace(/\s*[*xX]\s*10\s*(\^|\*\*)\s*/, "e");
306310

307-
return str.replace(/^([+-])?(\d+)\.?(\d*)[eE]([-+]?\d+)$/, function(x, s, n, f, c) {
308-
var l = +c < 0;
309-
var i = n.length + +c;
310-
x = (l ? n : f).length,
311-
c = ((c = Math.abs(c)) >= x ? c - x + l : 0),
312-
z = (new Array(c + 1)).join("0"), r = n + f;
311+
return str.replace(/^([+\-])?(\d+)\.?(\d*)[eE]([+\-]?\d+)$/, function(x, s, n, f, c) {
312+
c = +c;
313+
var l = c < 0;
314+
var i = n.length + c;
315+
x = (l ? n : f).length;
316+
c = ((c = Math.abs(c)) >= x ? c - x + l : 0);
317+
var z = (new Array(c + 1)).join("0");
318+
var r = n + f;
313319
return (s || "") + (l ? r = z + r : r += z).substr(0, i += l ? z.length : 0) + (i < r.length ? "." + r.substr(i) : "");
314320
});
315321
}
316322

317323
s = s.toString();
318-
if (base === undefined || base == 10) {
324+
if (base === undefined || +base === 10) {
319325
s = expandExponential(s);
320326
}
321327

322-
var parts = /^([-+]?)(0[xXbB]?)?([0-9A-Za-z]*)(?:\.\d*)?$/.exec(s);
328+
var parts = /^([+\-]?)(0[xXbB]?)?([0-9A-Za-z]*)(?:\.\d*)?$/.exec(s);
323329
if (parts) {
324330
var sign = parts[1] || "+";
325331
var baseSection = parts[2] || "";
@@ -350,6 +356,8 @@ BigInteger.parse = function(s, base) {
350356
throw new Error("Illegal radix " + base + ".");
351357
}
352358

359+
base = +base;
360+
353361
// Check for digits outside the range
354362
if (!(BigInteger.radixRegex[base].test(digits))) {
355363
throw new Error("Bad digit for radix " + base);
@@ -365,7 +373,7 @@ BigInteger.parse = function(s, base) {
365373
sign = (sign === "-") ? -1 : 1;
366374

367375
// Optimize base 10
368-
if (base == 10) {
376+
if (base === 10) {
369377
return new BigInteger(digits.map(Number).reverse(), sign);
370378
}
371379

@@ -848,7 +856,9 @@ BigInteger.prototype.multiplySingleDigit = function(n, cache) {
848856

849857
if (this._d.length === 1) {
850858
var digit = this._d[0] * n;
851-
if (digit > 9) return new BigInteger([(digit % 10)|0, (digit / 10)|0], 1);
859+
if (digit > 9) {
860+
return new BigInteger([(digit % 10)|0, (digit / 10)|0], 1);
861+
}
852862
cache[n] = BigInteger.small[digit];
853863
return cache[n];
854864
}
@@ -978,9 +988,12 @@ BigInteger.prototype.mod = function(n) {
978988
*/
979989
BigInteger.prototype.divMod = function(n) {
980990
n = BigInteger(n);
981-
if (n._s === 0) throw new Error("Divide by zero");
982-
983-
if (this._s === 0) return [BigInteger.ZERO, BigInteger.ZERO];
991+
if (n._s === 0) {
992+
throw new Error("Divide by zero");
993+
}
994+
if (this._s === 0) {
995+
return [BigInteger.ZERO, BigInteger.ZERO];
996+
}
984997
if (n._d.length === 1) {
985998
return this.divModSmall(n._s * n._d[0]);
986999
}
@@ -1013,7 +1026,7 @@ BigInteger.prototype.divMod = function(n) {
10131026
continue;
10141027
}
10151028
if (part._s === 0) {
1016-
guess = 0;
1029+
varguess = 0;
10171030
}
10181031
else {
10191032
var guess = 9;
@@ -1027,7 +1040,9 @@ BigInteger.prototype.divMod = function(n) {
10271040
} while (guess);
10281041

10291042
quot.push(guess);
1030-
if (!guess) continue;
1043+
if (!guess) {
1044+
continue;
1045+
}
10311046
var diff = part.subtract(check);
10321047
part._d = diff._d.slice();
10331048
}
@@ -1052,7 +1067,9 @@ BigInteger.prototype.divModSmall = function(n) {
10521067
throw new Error("Argument out of range");
10531068
}
10541069

1055-
if (this._s === 0) return [BigInteger.ZERO, BigInteger.ZERO];
1070+
if (this._s === 0) {
1071+
return [BigInteger.ZERO, BigInteger.ZERO];
1072+
}
10561073

10571074
if (n === 1 || n === -1) {
10581075
return [(sign === 1) ? this.abs() : new BigInteger(this._d, sign), BigInteger.ZERO];
@@ -1076,6 +1093,7 @@ BigInteger.prototype.divModSmall = function(n) {
10761093
var digits = this._d.slice();
10771094
var quot = new Array(digits.length);
10781095
var part = 0;
1096+
var diff = 0;
10791097
var i = 0;
10801098

10811099
while (digits.length) {
@@ -1094,7 +1112,7 @@ BigInteger.prototype.divModSmall = function(n) {
10941112
}
10951113

10961114
var check = n * guess;
1097-
vardiff = part - check;
1115+
diff = part - check;
10981116
quot[i++] = guess;
10991117
if (!guess) {
11001118
digits.pop();
@@ -1128,7 +1146,7 @@ BigInteger.prototype.divModSmall = function(n) {
11281146
*/
11291147
BigInteger.prototype.isEven = function() {
11301148
var digits = this._d;
1131-
return this._s === 0 || digits.length === 0 || (digits[0] % 2) === 0
1149+
return this._s === 0 || digits.length === 0 || (digits[0] % 2) === 0;
11321150
};
11331151

11341152
/*
@@ -1281,8 +1299,12 @@ BigInteger.prototype.exp10 = function(n) {
12811299
*/
12821300
BigInteger.prototype.pow = function(n) {
12831301
if (this.isUnit()) {
1284-
if (this._s > 0) return this;
1285-
else return BigInteger(n).isOdd() ? this : this.negate();
1302+
if (this._s > 0) {
1303+
return this;
1304+
}
1305+
else {
1306+
return BigInteger(n).isOdd() ? this : this.negate();
1307+
}
12861308
}
12871309

12881310
n = BigInteger(n);
@@ -1388,19 +1410,19 @@ BigInteger.MAX_EXP = BigInteger(0x7FFFFFFF);
13881410
function makeUnary(fn) {
13891411
return function(a) {
13901412
return fn.call(BigInteger(a));
1391-
}
1413+
};
13921414
}
13931415

13941416
function makeBinary(fn) {
13951417
return function(a, b) {
13961418
return fn.call(BigInteger(a), BigInteger(b));
1397-
}
1419+
};
13981420
}
13991421

14001422
function makeTrinary(fn) {
14011423
return function(a, b, c) {
14021424
return fn.call(BigInteger(a), BigInteger(b), BigInteger(c));
1403-
}
1425+
};
14041426
}
14051427

14061428
(function() {
@@ -1425,6 +1447,6 @@ BigInteger.MAX_EXP = BigInteger(0x7FFFFFFF);
14251447

14261448
BigInteger.exp10 = function(x, n) {
14271449
return BigInteger(x).exp10(n);
1428-
}
1450+
};
14291451
})();
14301452
})();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /