Sha256: b4c0f04450bc0c03d17795048c7285b9155c56c287199161f0cd08b5ba716d01

Contents?: true

Size: 642 Bytes

Versions: 295

Compression:

Stored size: 642 Bytes

Contents

class PhoneNumber {
    private value: string
    constructor(input: string) {
        let cleanedUp = input.replace(/(\)|\(|\s|\.|-)/g, "")
        if (cleanedUp.length === 11 && cleanedUp[0] === "1") {
            cleanedUp = cleanedUp.slice(1, 11)
        }
        this.value = cleanedUp
    }
    number(): string | undefined {
        if (this.value.length < 10 || this.value.length > 10 ) {
            return undefined
        }
        for (const each of this.value) {
           const result = parseInt(each, 10)
           if (isNaN(result)) {return undefined}
        }
        return this.value
    }
}
export default PhoneNumber

Version data entries

295 entries across 295 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.158 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.157 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.156 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.155 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.154 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.153 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.152 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.151 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.150 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.149 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.148 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.147 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.146 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.145 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.144 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.143 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.142 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.141 tracks/typescript/exercises/phone-number/phone-number.example.ts
trackler-2.2.1.140 tracks/typescript/exercises/phone-number/phone-number.example.ts