Sha256: 84f4a616483b4aa7f6773a5658903f4f3df95e0846b82d16e54b023008d444ff

Contents?: true

Size: 443 Bytes

Versions: 155

Compression:

Stored size: 443 Bytes

Contents

export default class PhoneNumber {

  constructor(number) {
    this.rawNumber = number;
  }

  number() {
    if(/[a-zA-Z]/.test(this.rawNumber)) {
      return null;
    }

    return this._cleanedNumber();
  }

  _cleanedNumber() {
    let num = this.rawNumber.replace(/\D/g,'');

    if (num.length === 10) {
      return num;
    }

    if (num.length === 11 && num[0] === '1') {
      return num.substr(1);
    }

    return null;
  }
}

Version data entries

155 entries across 155 versions & 1 rubygems

Version Path
trackler-2.2.0.0 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.55 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.54 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.53 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.52 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.51 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.50 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.49 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.48 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.47 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.46 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.45 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.44 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.43 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.42 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.41 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.40 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.39 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.38 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.37 tracks/ecmascript/exercises/phone-number/example.js