Files
learn_enough_javascript_cod…/Listing_5.18.js
T
2022-01-12 14:58:42 -08:00

24 lines
539 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
% const sonnet = `Let me not to the marriage of true minds
% .
% .
% .
% But bears it out even to the edge of doom.
% If this be error and upon me proved,
% I never writ, nor no man ever loved.`;
% // Unique words.
% let uniques = {};
% // All words in the text
% let words = sonnet.match(/[\w']+/g);
% // Iterate through `words` and build up a hash of unique words.
% words.forEach(function(word) {
% if (uniques[word]) {
% uniques[word] += 1;
% } else {
% uniques[word] = 1;
% }
% });
% console.log(uniques)