Sha256: a4f3ac5b71db58e548b0a91f37a226652925897f80c243b0b45e846a0ad6e6f0

Contents?: true

Size: 893 Bytes

Versions: 141

Compression:

Stored size: 893 Bytes

Contents

'use strict';

var Phone = module.exports = function Phone(number) {
  this.rawNumber = number;
  this.cleanedNumber = this.cleanNumber(number);
};

Phone.prototype.cleanNumber = function (number) {
  var num = number.replace(/\D/g, '');

  if (num.length === 10 && num[0] >= 2 && num[3] >= 2) {
    return num;
  } else if (num.length === 11 && num[0] === '1') {
    return num.substr(1, num.length);
  }
  return null;
};

Phone.prototype.number = function () {
  return this.cleanedNumber;
};

Phone.prototype.areaCode = function () {
  return this.number().substr(0, 3);
};

Phone.prototype.exchangeCode = function () {
  return this.number().substr(3, 3);
};

Phone.prototype.subscriberNumber = function () {
  return this.number().substr(6, 4);
};

Phone.prototype.toString = function () {
  return '(' + this.areaCode() + ') ' + this.exchangeCode() + '-' + this.subscriberNumber();
};

Version data entries

141 entries across 141 versions & 1 rubygems

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