Last active
June 25, 2021 22:23
-
-
Save airicbear/3a690e9f4527d4fde1716652031fc2d7 to your computer and use it in GitHub Desktop.
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
# 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