Sha256: 3cd39a81fd273ad6e082aac01c2b7f077b1cd838bbfa4f0eee17de7613ec7e3f
Contents?: true
Size: 567 Bytes
Versions: 74
Compression:
Stored size: 567 Bytes
Contents
/** * Here is an example solution for the WordCount exercise */ component { function countwords( sentence ) { return sentence // Strip out chars we don't care about .reReplaceNoCase( '[^a-z0-9'' ]', '', 'all' ) // Break string into array .listToArray( ' ' ) // Reduce arary into struct of word counts .reduce( function( wordStats, word ){ // Clean quoted words word = word.reReplaceNocase( "^'(.*)'$", "\1" ); // Aggregate word counts wordStats[ word ] = ( wordStats[ word ] ?: 0 ) + 1; return wordStats; }, {} ); } }
Version data entries
74 entries across 74 versions & 1 rubygems