Skip to content

Instantly share code, notes, and snippets.

@AnimaWish
Created April 3, 2012 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AnimaWish/2288986 to your computer and use it in GitHub Desktop.
Save AnimaWish/2288986 to your computer and use it in GitHub Desktop.
class String
def findchar(n)
self[n,1] #gets nth character
end
end
example = ['banana', 'elephant', 'apple', 'friday', 'cocaine', 'damage']
array = example
parray = Array.new
array.each do |item|
itempos = [item]
lengthey = (0..item.length) #range from 0 to n where n is the length
lengthey.each do |x| #do this for every letter in the word
position = item.findchar(x)#.ord #
itempos.push(position)
end
parray.push(itempos)
end
puts parray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment