FRUITS = {
1 => 'kiwi',
...
100 => 'pineapple'
}
def substract_sum(num)
if num >= 10 && num < 10000
sum_of_digits = num.to_s.chars.map(&:to_i).inject(:+)
if FRUITS.keys.include?(sum_of_digits)
puts FRUITS[sum_of_digits]
else
puts "#{sum_of_digits} (not in the list)"
end
else
puts 'Enter valid number'
end
end
substract_sum(10)
substract_sum(1204)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is Ruby solution,