Skip to content

Commit 9baca8b

Browse files
committed
Prevent not following the instructions
1 parent 3f3cdde commit 9baca8b

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

exercises/concept/train-driver/.meta/exemplar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function getListOfWagons(...ids) {
1717
/**
1818
* Reorder the array of wagons by moving the first 2 wagons to the end of the array.
1919
*
20-
* @param {number[]} ids
20+
* @param {Iterable<number>} ids
2121
* @returns {number[]} reordered list of wagons
2222
*/
2323
export function fixListOfWagons([first, second, ...rest]) {
@@ -27,8 +27,8 @@ export function fixListOfWagons([first, second, ...rest]) {
2727
/**
2828
* Fixes the array of wagons by inserting an array of wagons after the first element in eachWagonsID.
2929
*
30-
* @param {number[]} ids
31-
* @param {number[]} missingWagons
30+
* @param {Iterable<number>} ids
31+
* @param {Iterable<number>} missingWagons
3232
* @returns {number[]} corrected list of wagons
3333
*/
3434
export function correctListOfWagons([first, ...rest], missingWagons) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function getListOfWagons(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
1717
/**
1818
* Reorder the array of wagons by moving the first 2 wagons to the end of the array.
1919
*
20-
* @param {number[]} ids
20+
* @param {Iterable<number>} ids
2121
* @returns {number[]} reorderd list of wagons
2222
*/
2323
export function fixListOfWagons(ids) {
@@ -27,8 +27,8 @@ export function fixListOfWagons(ids) {
2727
/**
2828
* Fixes the array of wagons by inserting an array of wagons after the first element in eachWagonsID.
2929
*
30-
* @param {number[]} ids
31-
* @param {number[]} missingWagons
30+
* @param {Iterable<number>} ids
31+
* @param {Iterable<number>} missingWagons
3232
* @returns {number[]} corrected list of wagons
3333
*/
3434
export function correctListOfWagons(ids, missingWagons) {

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import {
88
separateTimeOfArrival,
99
} from './train-driver';
1010

11+
class LimitedArray {
12+
constructor(values) {
13+
this.values = values;
14+
}
15+
16+
[Symbol.iterator]() {
17+
return this.values[Symbol.iterator]();
18+
}
19+
}
20+
21+
function list(...values) {
22+
return new LimitedArray(values);
23+
}
24+
1125
describe('getListOfWagons', () => {
1226
test('returns the correct array', () => {
1327
expect(getListOfWagons(1, 5, 2, 7, 4)).toEqual([1, 5, 2, 7, 4]);
@@ -30,29 +44,29 @@ describe('getListOfWagons', () => {
3044

3145
describe('fixListOfWagons', () => {
3246
test('reorders the first 2 wagons to the end of the array', () => {
33-
const eachWagonsID = [3, 7, 1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19];
47+
const eachWagonsID = list(3, 7, 1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19);
3448
const expected = [1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19, 3, 7];
3549

3650
expect(fixListOfWagons(eachWagonsID)).toEqual(expected);
3751
});
3852

3953
test('works when only 3 wagons given', () => {
40-
const eachWagonsID = [4, 2, 1];
54+
const eachWagonsID = list(4, 2, 1);
4155

4256
expect(fixListOfWagons(eachWagonsID)).toEqual([1, 4, 2]);
4357
});
4458

4559
test('works for a few wagons', () => {
46-
const eachWagonsID = [3, 4, 1, 5, 7, 9, 10];
60+
const eachWagonsID = list(3, 4, 1, 5, 7, 9, 10);
4761

4862
expect(fixListOfWagons(eachWagonsID)).toEqual([1, 5, 7, 9, 10, 3, 4]);
4963
});
5064
});
5165

5266
describe('correctListOfWagons', () => {
5367
test('returns a wagon weight list with the inserted array of values', () => {
54-
const eachWagonsID = [1, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21];
55-
const missingWagons = [8, 10, 5, 9, 3, 7, 20];
68+
const eachWagonsID = list(1, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21);
69+
const missingWagons = list(8, 10, 5, 9, 3, 7, 20);
5670
const expected = [
5771
1, 8, 10, 5, 9, 3, 7, 20, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21,
5872
];
@@ -61,16 +75,16 @@ describe('correctListOfWagons', () => {
6175
});
6276

6377
test('works for short arrays', () => {
64-
const eachWagonsID = [1, 7, 15, 24];
65-
const missingWagons = [8, 6, 4];
78+
const eachWagonsID = list(1, 7, 15, 24);
79+
const missingWagons = list(8, 6, 4);
6680
const expected = [1, 8, 6, 4, 7, 15, 24];
6781

6882
expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected);
6983
});
7084

7185
test('works when missingWagons is longer', () => {
72-
const eachWagonsID = [1, 7, 15, 24];
73-
const missingWagons = [8, 6, 4, 5, 9, 21, 2, 13];
86+
const eachWagonsID = list(1, 7, 15, 24);
87+
const missingWagons = list(8, 6, 4, 5, 9, 21, 2, 13);
7488
const expected = [1, 8, 6, 4, 5, 9, 21, 2, 13, 7, 15, 24];
7589

7690
expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected);

0 commit comments

Comments
 (0)