DEV Community

Discussion on: Daily Challenge #189 - Convert Number into Reversed Array

Collapse
nijeesh4all profile image
Nijeesh Joshy • Edited on

ruby


def convert_nt_a number
  number
    .to_s
    .split('')
    .reverse
    .map { |num| num.to_i }
end


# TESTS

require "test/unit"

class ConvertNtATest < Test::Unit::TestCase
  def test_convert_nt_a
    assert_equal [7,9,5,8,4,3],  convert_nt_a(348597)
    assert_equal [4, 5, 5, 1, 8, 5, 6],  convert_nt_a(6581554)
    assert_equal [6, 5, 4, 3, 2, 1],  convert_nt_a(123456)
    assert_equal [3, 2, 1, 7, 8, 9], convert_nt_a(987123)
  end
end

#1 tests, 4 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications