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.139 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.138 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.137 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.136 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.135 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.134 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.133 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.132 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.131 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.130 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.129 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.128 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.127 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.126 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.125 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.124 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.123 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.122 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.121 tracks/typescript/exercises/sublist/sublist.example.ts
trackler-2.2.1.120 tracks/typescript/exercises/sublist/sublist.example.ts