Skip to content

Commit 51fae43

Browse files
committed
Add logging overrides
1 parent 9baca8b commit 51fae43

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

exercises/concept/train-driver/train-driver.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,42 @@ import {
88
separateTimeOfArrival,
99
} from './train-driver';
1010

11+
const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom');
12+
const customLogSymbol = Symbol.for('exercism.javascript.util.log');
13+
14+
// Follow the instructions in case you are stuck on "list.method is not a function"
1115
class LimitedArray {
1216
constructor(values) {
1317
this.values = values;
1418
}
1519

20+
// Enables rest syntax and spread operator, as wel as for of, etc.
1621
[Symbol.iterator]() {
1722
return this.values[Symbol.iterator]();
1823
}
24+
25+
// Log value in non-upgraded environments
26+
toString() {
27+
return this.values.toString();
28+
}
29+
30+
// Overrides logging in node (ie. students working locally)
31+
[customInspectSymbol](depth, inspectOptions, inspect) {
32+
const inner = this.values[customInspectSymbol]
33+
? this.values[customInspectSymbol](depth, inspectOptions, inspect)
34+
: this.values.toString();
35+
36+
return `List of (${inner})`;
37+
}
38+
39+
// Overrides log overrides in web environment (ie. students working in editor)
40+
[customLogSymbol](depth, inspectOptions, inspect) {
41+
const inner = this.values[customLogSymbol]
42+
? this.values[customLogSymbol](depth, inspectOptions, inspect)
43+
: this.values.toString();
44+
45+
return `List of (${inner})`;
46+
}
1947
}
2048

2149
function list(...values) {

0 commit comments

Comments
 (0)