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

Version Path
trackler-2.2.1.119 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.118 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.117 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.116 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.115 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.114 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.113 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.111 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.110 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.109 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.108 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.107 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.106 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.105 tracks/cfml/exercises/word-count/Solution.cfc