Skip to content

Instantly share code, notes, and snippets.

@gogogarrett
Created September 14, 2012 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gogogarrett/03d2186dd591cb17c114 to your computer and use it in GitHub Desktop.
Save gogogarrett/03d2186dd591cb17c114 to your computer and use it in GitHub Desktop.
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