-
-
Save gogogarrett/03d2186dd591cb17c114 to your computer and use it in GitHub Desktop.
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
def start_of_word word, letter | |
final = [] | |
word.chars.each_with_index do |c, i| | |
final << c if i < letter | |
end | |
final.join("") | |
end | |
-> start_of_word("hello", 1) | |
=> "h" | |
-> start_of_word("hello", 3) | |
=> "hel" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment