Change a bunch of uses of var to let

This commit is contained in:
Jesse Schwartzentruber 2017-04-10 13:36:38 -04:00
parent db1997c4ea
commit bdeabbbbd4
2 changed files with 19 additions and 19 deletions

View file

@ -17,8 +17,8 @@ function MersenneTwister()
const LOWER_MASK = 0x7fffffff; const LOWER_MASK = 0x7fffffff;
const MAG01 = new Int32Array([0, 0x9908b0df]); const MAG01 = new Int32Array([0, 0x9908b0df]);
var mt = new Int32Array(N); /* the array for the state vector */ let mt = new Int32Array(N); /* the array for the state vector */
var mti = 625; let mti = 625;
this.seed = function (s) { this.seed = function (s) {
mt[0] = s | 0; mt[0] = s | 0;
@ -53,7 +53,7 @@ function MersenneTwister()
}; };
this.int32 = function () { this.int32 = function () {
var y, kk; let y, kk;
if (mti >= N) { /* generate N words at one time */ if (mti >= N) { /* generate N words at one time */
for (kk = 0; kk < N-M; kk++) { for (kk = 0; kk < N-M; kk++) {

View file

@ -42,8 +42,8 @@ var random = {
return list[this.number(list.length)]; return list[this.number(list.length)];
}, },
key: function (obj) { key: function (obj) {
var list = []; let list = [];
for (var i in obj) { for (let i in obj) {
list.push(i); list.push(i);
} }
return this.index(list); return this.index(list);
@ -75,12 +75,12 @@ var random = {
Utils.traceback(); Utils.traceback();
throw new TypeError("random.choose() received a non-array type: '" + list + "'"); throw new TypeError("random.choose() received a non-array type: '" + list + "'");
} }
var total = 0; let total = 0;
for (var i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
total += list[i][0]; total += list[i][0];
} }
var n = this.number(total); let n = this.number(total);
for (var i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
if (n < list[i][0]) { if (n < list[i][0]) {
if (flat == true) { if (flat == true) {
return list[i][1]; return list[i][1];
@ -97,9 +97,9 @@ var random = {
}, },
weighted: function (wa) { weighted: function (wa) {
// More memory-hungry but hopefully faster than random.choose$flat // More memory-hungry but hopefully faster than random.choose$flat
var a = []; let a = [];
for (var i = 0; i < wa.length; ++i) { for (let i = 0; i < wa.length; ++i) {
for (var j = 0; j < wa[i].w; ++j) { for (let j = 0; j < wa[i].w; ++j) {
a.push(wa[i].v); a.push(wa[i].v);
} }
} }
@ -109,17 +109,17 @@ var random = {
return random.bool() ? obj : ""; return random.bool() ? obj : "";
}, },
shuffle: function (arr) { shuffle: function (arr) {
var len = arr.length; let len = arr.length;
var i = len; let i = len;
while (i--) { while (i--) {
var p = random.number(i + 1); let p = random.number(i + 1);
var t = arr[i]; let t = arr[i];
arr[i] = arr[p]; arr[i] = arr[p];
arr[p] = t; arr[p] = t;
} }
}, },
shuffled: function (arr) { shuffled: function (arr) {
var newArray = arr.slice(); let newArray = arr.slice();
random.shuffle(newArray); random.shuffle(newArray);
return newArray; return newArray;
}, },
@ -131,8 +131,8 @@ var random = {
if (typeof limit == 'number') { if (typeof limit == 'number') {
limit = this.range(0, list.length); limit = this.range(0, list.length);
} }
var result = []; let result = [];
for (var i = 0; i < limit; i++) { for (let i = 0; i < limit; i++) {
result.push(this.pick(list)); result.push(this.pick(list));
} }
return result; return result;