Skip to content

Commit c5f3778

Browse files
authored
Syncing test.toml and updating the test code and the proof solutions for sublist (#2651)
* Syncing test.toml and updating the test code and the proof solutions * running format.mjs
1 parent b988663 commit c5f3778

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

exercises/practice/sublist/.meta/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
],
55
"contributors": [
66
"ankorGH",
7+
"atk",
8+
"jagdish-15",
79
"rchavarria",
810
"SleeplessByte",
911
"tejasbubane",
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
export class List {
2-
constructor(list = []) {
3-
this.list = list;
2+
items = [];
3+
4+
constructor(...items) {
5+
this.items = items;
46
}
57

68
compare(other) {
7-
return {
8-
'-1': isSublist(other.list, this.list) ? 'SUBLIST' : 'UNEQUAL',
9-
0: isSublist(other.list, this.list) ? 'EQUAL' : 'UNEQUAL',
10-
1: isSublist(this.list, other.list) ? 'SUPERLIST' : 'UNEQUAL',
11-
}[lengthDiff(this, other)];
9+
const sublist =
10+
this.items.length === 0 ||
11+
`,${other.items.join(',')},`.includes(`,${this.items.join(',')},`);
12+
const superlist =
13+
other.items.length === 0 ||
14+
`,${this.items.join(',')},`.includes(`,${other.items.join(',')},`);
15+
return ['UNEQUAL', 'SUPERLIST', 'SUBLIST', 'EQUAL'][
16+
+superlist + (+sublist << 1)
17+
];
1218
}
1319
}
14-
15-
function lengthDiff(one, two) {
16-
return String(Math.sign(one.list.length - two.list.length));
17-
}
18-
19-
function isSublist(one, two) {
20-
return one.join().match(two.join());
21-
}

exercises/practice/sublist/.meta/tests.toml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[97319c93-ebc5-47ab-a022-02a1980e1d29]
613
description = "empty lists"
@@ -47,6 +54,9 @@ description = "first list missing element from second list"
4754
[83ffe6d8-a445-4a3c-8795-1e51a95e65c3]
4855
description = "second list missing element from first list"
4956

57+
[7bc76cb8-5003-49ca-bc47-cdfbe6c2bb89]
58+
description = "first list missing additional digits from second list"
59+
5060
[0d7ee7c1-0347-45c8-9ef5-b88db152b30b]
5161
description = "order matters to a list"
5262

exercises/practice/sublist/sublist.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ describe('sublist', () => {
107107
expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
108108
});
109109

110+
xtest('first list missing additional digits from second list', () => {
111+
const listOne = new List([1, 2]);
112+
const listTwo = new List([1, 22]);
113+
114+
expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
115+
});
116+
110117
xtest('order matters to a list', () => {
111118
const listOne = new List([1, 2, 3]);
112119
const listTwo = new List([3, 2, 1]);

0 commit comments

Comments
 (0)