Gistlib Logo

gistlib

one last example. write a function that gives the max value of digits in a number: if the number is 689 for instance, it should return 9. in ruby

main.rb
def max_digit(num)
  num.to_s.chars.map(&:to_i).max
end

puts max_digit(689)  # Output: 9
90 chars
6 lines

similar ruby code snippets

insert an element into an array at a specific index in ruby
remove an element from an array at a specific index in ruby
remove an element from the middle of an array in ruby
find the index of an element in an array in ruby
sort an array in ruby
remove an element from the beginning of an array in ruby
add an element to the beginning of an array in ruby
add an element to the end of an array in ruby
remove an element from the end of an array in ruby
reverse an array in ruby

related categories

ruby

gistlibby LogSnag