Skip to content

Commit 4e27669

Browse files
committed
Code style
1 parent a217b1e commit 4e27669

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

JavaScript/1-range.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class Range {
2626
current >= end && step > 0 ||
2727
current <= end && step < 0
2828
) {
29-
let value = current;
29+
const value = current;
3030
current = undefined;
3131
return { value, done: true };
3232
}
3333

34-
let value = current;
34+
const value = current;
3535
current += step;
3636
return { value, done: false };
3737
}

JavaScript/2-range-generator.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

33
function* range(first, second, step = 1) {
4-
let current;
5-
let end;
4+
let current, end;
65

76
if (second === undefined) {
87
current = 0;
@@ -12,13 +11,18 @@ function* range(first, second, step = 1) {
1211
end = second;
1312
}
1413

15-
while (
16-
current < end && step > 0 ||
17-
current > end && step < 0
18-
) {
19-
yield current;
20-
current += step;
14+
if (step > 0) {
15+
while (current < end) {
16+
yield current;
17+
current += step;
18+
}
19+
} else {
20+
while (current > end) {
21+
yield current;
22+
current += step;
23+
}
2124
}
25+
2226
}
2327

2428
console.log([
@@ -27,9 +31,3 @@ console.log([
2731
[...range(2, 15, 2)],
2832
[...range(10, 0, -1)],
2933
]);
30-
31-
/*
32-
for (let x of range(10, Infinity, 3000000000000)) {
33-
console.dir({ x });
34-
}
35-
*/

JavaScript/3-primes.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ function* numbers(start) {
77
}
88

99
function* sieve(sequence, prime) {
10-
for (let number of sequence) {
10+
for (const number of sequence) {
1111
if (number % prime !== 0) {
1212
yield number;
1313
}
1414
}
1515
}
1616

1717
function* primes() {
18-
var sequence = numbers(2);
18+
let sequence = numbers(2);
19+
let prime;
1920
while (true) {
20-
let prime = sequence.next().value;
21+
prime = sequence.next().value;
2122
yield prime;
2223
sequence = sieve(sequence, prime);
2324
}
@@ -29,6 +30,6 @@ function* take(count, sequence) {
2930
}
3031
}
3132

32-
for (var prime of take(10, primes())) {
33+
for (const prime of take(10, primes())) {
3334
console.log(prime);
3435
}

JavaScript/4-producer-consumer.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
function* sleep(interval) {
4-
let start = new Date();
4+
const start = new Date();
55
while (new Date() - start < interval) {
66
yield;
77
}
@@ -16,13 +16,15 @@ function* consume() {
1616
let count = 0;
1717
let sum = 0;
1818
while (true) {
19-
let data = yield* produce();
19+
const data = yield* produce();
2020
count++;
2121
sum += data;
22-
console.log(`Got data: ${data}\n` +
23-
`Count: ${count}\n` +
24-
`Sum: ${sum}\n` +
25-
`Average: ${sum / count}\n`);
22+
console.log(
23+
`Got data: ${data}\n` +
24+
`Count: ${count}\n` +
25+
`Sum: ${sum}\n` +
26+
`Average: ${sum / count}\n`
27+
);
2628
}
2729
}
2830

@@ -33,14 +35,13 @@ function* anotherTask() {
3335
}
3436
}
3537

36-
let consumer = consume();
37-
let task = anotherTask();
38+
const consumer = consume();
39+
const task = anotherTask();
3840

39-
function step() {
41+
const step = () => {
4042
consumer.next();
4143
task.next();
42-
4344
setImmediate(step);
44-
}
45+
};
4546

4647
step();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy