Ad
  • Custom User Avatar

    I like is_a? and instance_of? more than ===, it is implicit

  • Custom User Avatar
  • Custom User Avatar
      begin
        button = Integer(button)
        level = Integer(level)  
      rescue
        return 0
      end
    

    using rescue to assure input is correct type

    ** Is it a correct or normal ruby way? **

  • Custom User Avatar

    Test.expect(solution((1..3).to_a, 1, 'a') == 2)
    Test.expect(solution((1..3).to_a, -1, 'a') == 3, 'Using a negative index returned the wrong value.')
    Test.expect(solution((1..3).to_a, -5, 'a') == 'a', 'Using a negative index returned the wrong value.')
    Test.expect(solution((1..3).to_a, -3, 'a') == 1, 'Using a negative index returned the default value when it should have returned the first value within the array.')
    Test.expect(solution((1..5).to_a, 10, 'a') == 'a', 'solution did not return default value when given an index that was out of range')
    Test.expect(solution([nil, nil], 0, 'a') == nil, "solution([nil, nil], 0, 'a') should have returned nil but instead got #{solution([nil, nil], 0, 'a') || 'nil'}")

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution