Last active
August 14, 2024 09:56
-
-
Save delasy/e4acadd31c44d7931c7d91f13f84625f to your computer and use it in GitHub Desktop.
Words counter made in The programming language
This file contains hidden or 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
#!/usr/bin/env the run | |
const CWD := process_cwd() + path_SEP | |
const IGNORE_LIST := ["build"] | |
fn traverse (path := "") str[] { | |
entities := fs_scandirSync(CWD + path) | |
pathPrefix := path.empty ? "" : path + path_SEP | |
mut result: str[] | |
loop i := entities.len - 1; i >= 0; i-- { | |
entity := entities[i] | |
entityPath := pathPrefix + entity | |
if entity.slice(0, 1) == "." || IGNORE_LIST.contains(entityPath) { | |
continue | |
} | |
if fs_isDirectorySync(entityPath) { | |
result.merge(traverse(entityPath)) | |
continue | |
} | |
result.push(CWD + entityPath) | |
} | |
return result | |
} | |
main { | |
files := traverse() | |
mut words := 0 | |
loop i := files.len - 1; i >= 0; i-- { | |
file := files[i] | |
words += fs_readFileSync(file).str().split("word").len - 1 | |
} | |
print("Count:", words) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment