diff --git a/exercises/practice/sublist/.meta/config.json b/exercises/practice/sublist/.meta/config.json index 064b6ac888..502e8e0c84 100644 --- a/exercises/practice/sublist/.meta/config.json +++ b/exercises/practice/sublist/.meta/config.json @@ -4,6 +4,8 @@ ], "contributors": [ "ankorGH", + "atk", + "jagdish-15", "rchavarria", "SleeplessByte", "tejasbubane", diff --git a/exercises/practice/sublist/.meta/proof.ci.js b/exercises/practice/sublist/.meta/proof.ci.js index b6ceb8fe8d..10d49b49a7 100644 --- a/exercises/practice/sublist/.meta/proof.ci.js +++ b/exercises/practice/sublist/.meta/proof.ci.js @@ -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()); -} diff --git a/exercises/practice/sublist/.meta/tests.toml b/exercises/practice/sublist/.meta/tests.toml index 74bd60cce7..de5020a9dd 100644 --- a/exercises/practice/sublist/.meta/tests.toml +++ b/exercises/practice/sublist/.meta/tests.toml @@ -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" @@ -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" diff --git a/exercises/practice/sublist/sublist.spec.js b/exercises/practice/sublist/sublist.spec.js index 227019e890..e290fc1de9 100644 --- a/exercises/practice/sublist/sublist.spec.js +++ b/exercises/practice/sublist/sublist.spec.js @@ -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]);