Skip to content

Comment on Simple Is Not Small

Comments

I think that you can elegantly implement the second problem in bash:

  grep -Eo '[A-Za-z]+' README.md \
      | tr A-Z a-z \
      | {
      distinct=()
      declare -A freqs
      while read word; do
          [[ -v freqs["$word"] ]] || distinct+=("$word")
          ((freqs["$word"]++))
      done 
      for word in "${distinct[@]}"; do
          echo "${freqs["$word"]}" "$word"
      done
  }
Used grep here because the original pipeline erroneously introduces an empty line when the file starts with a character that doesn't match '[:alpha:]'.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.