Sha256: 6f41a00d15fc586822ac79b34a33b1d80d0c0ef7123168b9a9d00e3426b1d511
Contents?: true
Size: 894 Bytes
Versions: 132
Compression:
Stored size: 894 Bytes
Contents
/** * Here is an example solution for the Anagram exercise */ component { function anagrams( string subject, array candidates ) { var results = []; for (var candidate in candidates) { /* Check if the canidate is an anagram and is not already in the results */ if ( isAnagram( subject, candidate ) && !results.find( lcase( candidate ) ) ) { results.append( lcase(candidate) ); } } return results; } /** * * Is an anagram and canidate is not the exact same as the subject * */ private boolean function isAnagram( string subject, string candidate ) { return ( sortString( candidate ) == sortString( subject ) && lcase( candidate ) != lcase( subject ) ); } /** * * Sort the characters in a string alphabetically * */ private string function sortString( string word ) { return listSort( lcase( arguments.word ), "text", "asc", "" ); } }
Version data entries
132 entries across 132 versions & 1 rubygems