practice-problems-1/no_comments/12-dasherize-number.rb
# Write a method that takes in a number and returns a string, placing
# a single dash before and after each odd digit. There is one
# exception: don't start or end the string with a dash.
#
# You may wish to use the `%` modulo operation; you can see if a number
# is even if it has zero remainder when divided by two.
#
# Difficulty: medium.
Write a method that takes in a number and returns a string, placing
a single dash before and after each odd digit. There is one
exception: don't start or end the string with a dash.

You may wish to use the `%` modulo operation; you can see if a number
is even if it has zero remainder when divided by two.

medium.
Write a method that takes in a number and returns a string placing a single dash before and after each odd digit . There is one exception : don ' t start or end the string with a dash . You may wish to use the ` % ` modulo operation ; you can see if a number is even if it has zero remainder when divided by two . medium .
def dasherize_number(num)
  nums = num.to_s.split('')
  nums.map! do |i|
    if i.to_i.odd? == true
      i = "-"+ i 
    end
    i.to_s
  end
  if nums[0].to_i.odd?
    nums[0].reverse!
  end
nums = nums.join('').split('')
 nums.map! do |k|
   index = nums.index(k)
    if nums[index] == "-" && nums[index+1] == "-"
        nums.delete_at(index)
    end
    k =k
 end
  return nums.join('')
end
def dasherize_number ( num ) nums = num . to_s . split ( '' ) nums . map! do | i | if i . to_i . odd? == true i = "-" + i end i . to_s end if nums [ 0 ] . to_i . odd? nums [ 0 ] . reverse! end nums = nums . join ( '' ) . split ( '' ) nums . map! do | k | index = nums . index ( k ) if nums [ index ] == "-" && nums [ index + 1 ] == "-" nums . delete_at ( index ) end k = k end return nums . join ( '' ) end
Write a method that takes in a number and returns a string, placing
a single dash before and after each odd digit.
Write a method that takes in a number and returns a string placing a single dash before and after each odd digit .
num
<not_specific>