Created
March 30, 2018 22:48
-
-
Save mattwr18/49632aba473f6ab714fc01ee5ead6988 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
require 'pry' | |
def fear_not_letter(str) | |
arr = str.upcase.each_char.map { |i| i.ord }.sort | |
miss_arr = [] | |
x = 0 | |
next_num = arr[0].next | |
arr.each do |curr_num| | |
if curr_num > next_num | |
(next_num...curr_num).each { |n| miss_arr << n unless miss_arr.include?(n) || arr.include?(n) } | |
else | |
next_num = arr[x].next | |
x += 1 | |
end | |
end | |
if miss_arr.empty? | |
"undefined" | |
else | |
miss_arr.map { |i| puts i.chr }.join('') | |
end | |
end | |
puts fear_not_letter("abce") # => d | |
puts fear_not_letter("ab") # => "undefined" | |
puts fear_not_letter("acegikmoqsuwy") # => bdfhjlnprtvx | |
puts fear_not_letter("acegiy") # => bdfhjklmnopqurstuvwx | |
puts fear_not_letter("afy") # => bcdeghijklmnopqurstuvwx | |
puts fear_not_letter("a") # => undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment