Created
April 3, 2012 03:05
-
-
Save AnimaWish/2288986 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
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