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.180 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.179 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.178 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.177 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.176 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.175 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.174 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.173 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.172 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.171 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.170 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.169 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.167 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.166 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.165 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.164 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.163 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.162 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.161 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.160 tracks/cfml/exercises/word-count/Solution.cfc