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.2.1.17 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.16 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.15 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.14 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.13 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.12 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.11 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.10 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.9 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.8 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.7 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.6 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.5 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.4 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.3 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.2 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.1 tracks/javascript/exercises/word-count/example.js
trackler-2.2.1.0 tracks/javascript/exercises/word-count/example.js
trackler-2.2.0.6 tracks/javascript/exercises/word-count/example.js
trackler-2.2.0.5 tracks/javascript/exercises/word-count/example.js