Sha256: 8abbbff932baf5d416fe67b159db21a48dd57fb4c8fbee9271b2d3c91390d548

Contents?: true

Size: 807 Bytes

Versions: 62

Compression:

Stored size: 807 Bytes

Contents

class List {
    list: number[]

    constructor(...list: number[]) {
        this.list = list
    }

    compare(other: List) {
        switch (this.lengthDiff(this, other)) {
            case '-1':
                return this.isSublist(other.list, this.list) ? 'sublist' : 'unequal'
            case '0':
                return this.isSublist(other.list, this.list) ? 'equal' : 'unequal'
            case '1':
                return this.isSublist(this.list, other.list) ? 'superlist' : 'unequal'
        }

        return 'unequal'
    }

    lengthDiff(listOne: List, listTwo: List) {
        return String(Math.sign(listOne.list.length - listTwo.list.length))
    }

    isSublist(listOne: number[], listTwo: number[]) {
        return listOne.join().match(listTwo.join())
    }
}

export default List

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.179 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.178 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.177 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.176 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.175 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.174 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.173 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.172 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.171 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.170 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.169 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.167 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.166 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.165 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.164 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.163 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.162 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.161 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.160 tracks/typescript/exercises/sublist/sublist.example.ts