Sha256: 026dc0931c6b2339779adad73d671f97723d1e322296106053b429550b129372

Contents?: true

Size: 446 Bytes

Versions: 225

Compression:

Stored size: 446 Bytes

Contents

'use strict';

function Words() {}

Words.prototype.count = function (input) {
  var counts = {};
  var words = input.toLowerCase()
                   .replace(/[,."\/!&@$%\^\*;:{}()¡¿?]/g, ' ')
                   .replace(/\s'(\w+)'\s/, ' '+'$1'+' ')
                   .match(/\S+/g);

  words.forEach(function (word) {
    counts[word] = counts.hasOwnProperty(word) ? counts[word] + 1 : 1;
  });
  return counts;
};

module.exports = Words;

Version data entries

225 entries across 225 versions & 1 rubygems

Version Path
trackler-2.1.0.40 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.39 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.38 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.37 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.36 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.34 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.33 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.32 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.31 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.30 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.29 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.28 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.27 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.26 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.25 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.24 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.23 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.22 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.21 tracks/javascript/exercises/word-count/example.js
trackler-2.1.0.20 tracks/javascript/exercises/word-count/example.js