Ad
  • Custom User Avatar

    Use of deconstruct for spliting world
    Use of backticks for join
    Use of sort rather than reverse
    Writing of a basic test

  • Custom User Avatar

    Golfing on the variable name
    Use of count method
    Use of an direct return
    Condition without if/else

  • Custom User Avatar

    The return True is not neccessary.

  • Custom User Avatar
  • Custom User Avatar

    Cool quotes

  • Custom User Avatar

    The goal is to learn with extra eyes on a problem.

  • Custom User Avatar

    An other approach is the use of regexp - I've posted my solution.

  • Custom User Avatar

    It's seems doesn't work in older ruby version. I've tried with 2.2.3 version, it's a syntax error.
    Maybe this is not a tick for production but quite nice trick.

  • Custom User Avatar

    I don't clearly understand this error

     `<': comparison of String with 0 failed (ArgumentError)
    	from `Ackermann'
    	from  `
    '
    
  • Custom User Avatar

    I'm quite puzzled, I think I've made all the test cases and I've created new ones but my final submit doesn't work

    Test.assert_equals(reverse_it('Hello'), "olleH", 'Not quite')
    Test.assert_equals(reverse_it("314159"), "951413", 'Not quite')
    Test.assert_equals(reverse_it(314159), 951413, 'Not quite')
    Test.assert_equals(reverse_it([]), [], 'Not quite')
    Test.assert_equals(reverse_it(true),false, 'Not quite')
    Test.assert_equals(reverse_it(false),true, 'Not quite')
    Test.assert_equals(reverse_it(nil),true, 'Not quite')
    Test.assert_equals(reverse_it(!nil),false, 'Not quite')
    
    

    I've got this

    Test Passed: Value == "olleH"
    Test Passed: Value == 951413
    Test Passed: Value == "951413"
    Test Passed: Value == []
    Test Passed: Value == {}
    Not quite - Expected: true, instead got: false
    
    

    My solution for now is quite dirty but it works in the first test but not for the final:

    def reverse_it(data)
      return data.to_s.reverse.to_i if (data.class)== Fixnum
      return data.to_a.reverse.to_h if (data.class)== Hash
      return data.reverse if (data.class)== String
      return data.reverse if (data.class)== Array
      return false if data.class == TrueClass
      return true if data.class == FalseClass
      return false if data == !nil
      return true if data == nil
    end