Sha256: 930843903c86a1777ee8cbb842b8e51fbe8fabad0df5b6a703f95e7c9a611b0d

Contents?: true

Size: 890 Bytes

Versions: 52

Compression:

Stored size: 890 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);
  } else {
    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

52 entries across 52 versions & 1 rubygems

Version Path
trackler-2.2.1.37 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.36 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.35 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.34 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.33 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.32 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.31 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.30 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.29 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.28 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.27 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.26 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.25 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.24 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.23 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.22 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.21 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.20 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.19 tracks/javascript/exercises/phone-number/example.js
trackler-2.2.1.18 tracks/javascript/exercises/phone-number/example.js