Skip to content

Instantly share code, notes, and snippets.

@airicbear
Last active June 25, 2021 22:23
Show Gist options
  • Save airicbear/3a690e9f4527d4fde1716652031fc2d7 to your computer and use it in GitHub Desktop.
Save airicbear/3a690e9f4527d4fde1716652031fc2d7 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
# Counts each
def substrings(string, valid_substrings)
downcase_string = string.downcase
Hash[
valid_substrings
.collect { |substring| [substring, downcase_string.scan(substring).length] }
.reject { |_substring, substring_length| substring_length.zero? }
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment