Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exercises/practice/sublist/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
],
"contributors": [
"ankorGH",
"atk",
"jagdish-15",
"rchavarria",
"SleeplessByte",
"tejasbubane",
Expand Down
28 changes: 13 additions & 15 deletions exercises/practice/sublist/.meta/proof.ci.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
export class List {
constructor(list = []) {
this.list = list;
items = [];

constructor(...items) {
this.items = items;
}

compare(other) {
return {
'-1': isSublist(other.list, this.list) ? 'SUBLIST' : 'UNEQUAL',
0: isSublist(other.list, this.list) ? 'EQUAL' : 'UNEQUAL',
1: isSublist(this.list, other.list) ? 'SUPERLIST' : 'UNEQUAL',
}[lengthDiff(this, other)];
const sublist =
this.items.length === 0 ||
`,${other.items.join(',')},`.includes(`,${this.items.join(',')},`);
const superlist =
other.items.length === 0 ||
`,${this.items.join(',')},`.includes(`,${other.items.join(',')},`);
return ['UNEQUAL', 'SUPERLIST', 'SUBLIST', 'EQUAL'][
+superlist + (+sublist << 1)
];
}
}

function lengthDiff(one, two) {
return String(Math.sign(one.list.length - two.list.length));
}

function isSublist(one, two) {
return one.join().match(two.join());
}
16 changes: 13 additions & 3 deletions exercises/practice/sublist/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

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

[7bc76cb8-5003-49ca-bc47-cdfbe6c2bb89]
description = "first list missing additional digits from second list"

[0d7ee7c1-0347-45c8-9ef5-b88db152b30b]
description = "order matters to a list"

Expand Down
7 changes: 7 additions & 0 deletions exercises/practice/sublist/sublist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ describe('sublist', () => {
expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
});

xtest('first list missing additional digits from second list', () => {
const listOne = new List([1, 2]);
const listTwo = new List([1, 22]);

expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
});

xtest('order matters to a list', () => {
const listOne = new List([1, 2, 3]);
const listTwo = new List([3, 2, 1]);
Expand Down