forked from adrianeyre/codewars
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindLetter.rb
More file actions
27 lines (20 loc) · 713 Bytes
/
FindLetter.rb
File metadata and controls
27 lines (20 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
=begin
Write a method that takes an array of consecutive (increasing) letters
as input and that returns the missing letter in the array.
You will always get an valid array. And it will be always exactly
one letter be missing. The length of the array will always be at least 2.
The array will always contain letters in only one case.
Example:
['a','b','c','d','f'] -> 'e'
['O','Q','R','S'] -> 'P'
=end
# My Solution
def find_missing_letter(arr)
(arr.length-1).times {|num| return (arr[num].ord+1).chr if arr[num].ord+1 != arr[num+1].ord}
return nil
end
# Other Solution
def find_missing_letter(arr)
arr[0...-1].each_with_index { |val, ind| return val.next if val.next != arr[ind+1] }
return nil
end