Sha256: 6bef662e461de242211bb61c5ff9c00ccdebd1491b68df2f895ea04034f6781e

Contents?: true

Size: 561 Bytes

Versions: 70

Compression:

Stored size: 561 Bytes

Contents

/**
* Here is an example solution for the WordCount exercise
*/
component {
		
	function countwords( input ) {
		return input
			// 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

70 entries across 69 versions & 1 rubygems

Version Path
trackler-2.2.1.104 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.103 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.102 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.101 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.100 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.99 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.98 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.97 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.96 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.95 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.94 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.93 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.92 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.91 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.90 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.89 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.88 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.87 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.86 tracks/cfml/exercises/word-count/Solution.cfc
trackler-2.2.1.85 tracks/cfml/exercises/word-count/Solution.cfc