Skip to content

Instantly share code, notes, and snippets.

@kkchu791
Created March 18, 2016 00:02
Show Gist options
  • Save kkchu791/ddeb240abe8b4c157816 to your computer and use it in GitHub Desktop.
Save kkchu791/ddeb240abe8b4c157816 to your computer and use it in GitHub Desktop.
def count_num(arr)
arr.each_with_object({}) { |i, hash| hash[i] = arr.count(i) }
end
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
class CountTest < Minitest::Test
def test_count
count = count_num([1, 1, 1, 2, 5, 5])
correct_count = { 1 => 3, 2 => 1, 5 => 2 }
assert_equal correct_count, count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment