Ruby - Enumerable - group_by

Sort by

recency

|

40 Discussions

|

  • + 0 comments
    def group_by_marks(marks, pass_marks)
          marks.group_by {|key, x| (x >= pass_marks) == true  ? "Passed" : "Failed" }
    end
    
  • + 0 comments
    def group_by_marks(marks, pass_marks)
      # your code here
        return marks.group_by do |k,v| 
            if v>= pass_marks
                next "Passed"
            else
                next "Failed"
            end
        end
    end
    
  • + 0 comments

    Hackerrank cannot decipher :Passed or :Failed when written as a symbol as opposed to in quotation marks. Changed to "Passed" and "Failed" instead and was able to pass the tests.

  • + 0 comments

    def group_by_marks(marks, pass_marks)

    data = marks.group_by { |_,mark| mark >= pass_marks}  
    result = {}
    result["Passed"] = data[true] unless data[true].nil?
    result["Failed"] = data[false] unless data[false].nil?
    result
    

    end

  • + 0 comments
    def group_by_marks(marks, pass_marks)
        # your code here
        marks.group_by do |name, score|
            score < pass_marks ? "Failed" : "Passed"
        end
    end