Created
April 16, 2013 07:47
-
-
Save Crenshinibon/5394158 to your computer and use it in GitHub Desktop.
Find isogram in local file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
filePath = process.argv[2] | |
start = new Date() | |
fs.readFile filePath, 'utf8', (error, data) -> | |
if not error | |
longest = [] | |
word = [] | |
isIso = true | |
for i in [0.. data.length] | |
l = data[i]?.toLowerCase() | |
if l and l.match /[a-z]/ | |
isIso = isIso and l not in word | |
if isIso then word.push l | |
else | |
if isIso and word.length > longest.length | |
longest = word | |
word = [] | |
isIso = true | |
console.log "Longest Isogram found: #{longest.reduce ((s, e) -> s + e), ''}" | |
console.log "in #{(new Date()).getTime() - start.getTime()} ms" | |
else | |
console.log error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment