Skip to content

Commit 5409da3

Browse files
committed
Use const instead of let whenever appropriate
1 parent 2cce5db commit 5409da3

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

multi-integer-range.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ export class MultiRange {
5252
return parseInt(str.match(/^\(?(\-?\d+)/)[1], 10);
5353
}
5454

55-
let s = data.replace(/\s/g, '');
55+
const s = data.replace(/\s/g, '');
5656
if (s.length === 0) return;
5757
for (let r of s.split(',')) {
5858
let match = r.match(/^(\d+|\(\-?\d+\))(\-(\d+|\(\-?\d+\)))?$/);
5959
if (match) {
60-
let min = toInt(match[1]);
61-
let max = typeof match[3] !== 'undefined' ? toInt(match[3]) : min;
60+
const min = toInt(match[1]);
61+
const max = typeof match[3] !== 'undefined' ? toInt(match[3]) : min;
6262
this.appendRange(min, max);
6363
} else {
6464
throw new SyntaxError('Invalid input');
@@ -99,7 +99,7 @@ export class MultiRange {
9999
if (newRange[0] > newRange[1]) {
100100
newRange = [newRange[1], newRange[0]];
101101
}
102-
let overlap = this.findOverlap(newRange);
102+
const overlap = this.findOverlap(newRange);
103103
this.ranges.splice(overlap.lo, overlap.count, overlap.union);
104104
return this;
105105
}
@@ -131,9 +131,9 @@ export class MultiRange {
131131
if (newRange[0] > newRange[1]) {
132132
newRange = [newRange[1], newRange[0]];
133133
}
134-
let overlap = this.findOverlap(newRange);
134+
const overlap = this.findOverlap(newRange);
135135
if (overlap.count > 0) {
136-
let remain = [];
136+
const remain = [];
137137
if (this.ranges[overlap.lo][0] < newRange[0]) {
138138
remain.push([this.ranges[overlap.lo][0], newRange[0] - 1]);
139139
}
@@ -153,16 +153,16 @@ export class MultiRange {
153153
if (value === undefined) {
154154
throw new TypeError('Invalid input');
155155
} else if (value instanceof MultiRange) {
156-
let result = [];
156+
const result = [];
157157
let jstart = 0; // used for optimization
158158
for (let i = 0; i < this.ranges.length; i++) {
159-
let r1 = this.ranges[i];
159+
const r1 = this.ranges[i];
160160
for (let j = jstart; j < value.ranges.length; j++) {
161-
let r2 = value.ranges[j];
161+
const r2 = value.ranges[j];
162162
if (r1[0] <= r2[1] && r1[1] >= r2[0]) {
163163
jstart = j;
164-
let min = Math.max(r1[0], r2[0]);
165-
let max = Math.min(r1[1], r2[1]);
164+
const min = Math.max(r1[0], r2[0]);
165+
const max = Math.min(r1[1], r2[1]);
166166
result.push([min, max]);
167167
} else if (r1[1] < r2[0]) {
168168
break;
@@ -206,7 +206,7 @@ export class MultiRange {
206206
// meaning (C) is between (2) and (3) but overlaps/touches neither of them.
207207

208208
for (let hi = this.ranges.length - 1; hi >= 0; hi--) {
209-
let r = this.ranges[hi];
209+
const r = this.ranges[hi];
210210
let union;
211211
if (union = this.calcUnion(r, target)) {
212212
let count = 1;
@@ -246,7 +246,7 @@ export class MultiRange {
246246
*/
247247
public getRanges(): Range[]
248248
{
249-
let result = []
249+
const result = []
250250
for (let r of this.ranges) result.push(<Range>[r[0], r[1]]);
251251
return result;
252252
}
@@ -261,8 +261,8 @@ export class MultiRange {
261261
if (value === undefined) {
262262
throw new TypeError('Invalid input');
263263
} else if (value instanceof MultiRange) {
264-
let s = 0;
265-
let len = this.ranges.length;
264+
const s = 0;
265+
const len = this.ranges.length;
266266
for (let tr of value.ranges) {
267267
let i: number;
268268
for (i = s; i < len; i++) {
@@ -364,7 +364,7 @@ export class MultiRange {
364364
*/
365365
public toArray(): number[]
366366
{
367-
let result = new Array(this.length());
367+
const result = new Array(this.length());
368368
let idx = 0;
369369
for (let r of this.ranges) {
370370
for (let n = r[0]; n <= r[1]; n++) {
@@ -385,7 +385,7 @@ export class MultiRange {
385385
return {
386386
next: () => {
387387
if (!curRange) return { done: true, value: undefined };
388-
let ret = j;
388+
const ret = j;
389389
if (++j > curRange[1]) {
390390
curRange = this.ranges[++i];
391391
j = curRange ? curRange[0] : undefined;

0 commit comments

Comments
 (0)