Skip to content

Instantly share code, notes, and snippets.

@mattwr18
Created March 30, 2018 22:48
Show Gist options
  • Save mattwr18/49632aba473f6ab714fc01ee5ead6988 to your computer and use it in GitHub Desktop.
Save mattwr18/49632aba473f6ab714fc01ee5ead6988 to your computer and use it in GitHub Desktop.
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