Ad
  • Custom User Avatar

    Using count instead of size or length makes a huge difference: count traverses an Enumerable, so you're losing a lot of CPU time for nothing, especially on large collections.

    http://batsov.com/articles/2014/02/17/the-elements-of-style-in-ruby-number-13-length-vs-size-vs-count/

  • Custom User Avatar

    Oh, so I wasn't the only one with that solution. :D

  • Custom User Avatar

    I appreciate the praise :)

  • Custom User Avatar

    Yes I know it, thank you :D

  • Custom User Avatar
  • Custom User Avatar

    Added a few more test cases to cover that :)

  • Default User Avatar

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

  • Custom User Avatar

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

  • Default User Avatar

    That's actually one of the things that got me hooked on this site. I don't think I've noticed anyone being less than cool.

  • Custom User Avatar

    These are good points. The down vote ability will probably go away at some point, we just haven't gotten around to updates in that area yet. Down votes are probably going away and will be replaced by the ability to flag, which initially will basically be the same as a down vote except that you have to earn the privilege to use it. Later on we will probably incorporate something more intelligent so that flagging is weighted by some sort of vote reputation.

    Fortunately, so far no one really seems to be abusing the down vote ability. Everyone has been pretty... honorable.

  • Default User Avatar

    I feel like down votes almost always sometimes tend to degrade into a method of 'punishing' people for having a different viewpoint. It's one of the main reasons I don't have a StackExchange/Overflow account. Personally, I reserve down votes for spam and/or abusive comments. If I feel someone else is factually incorrect I'd be more inclined to write a reply citing why I disagree with them. That way, when I'm wrong I have an opportunity to learn something new when someone that's correct replies.

    I'd suggest taking a look at how a few other communities handle up/down votes.

    Check out Daniweb. They use some form of algorithm where the effect your vote has on a post is determined by how many up/down votes your posts have received.

    Newgrounds has a feature that could be adapted. Users can flag submissions/reviews as being against the ToS. When a submission gets reviewed, the results of the review affect a stat of the user(s) that flagged it. If you flag too many items that shouldn't have been flagged, your down votes don't affect a submission. It stays that way until you get in the habit of only flagging things that should be flagged.

    I think Reddit does a good job with hidden comments too. When a comment drops below a threshold score, it shows up as something along the lines of "This comment has been hidden due to downvotes [show]".

  • Custom User Avatar
  • Custom User Avatar

    OK. How about this?

    Complete the method so that it converts a hash of values into integer percentages, where the individual percentages should be rounded to the nearest integer.

    Due to rounding, the total sum might not equal 100.

    The method should take an optional set of keys as a second argument that allows only a subset of the hash values to be converted.

  • Custom User Avatar

    Stupid me - it will be difficult to return the array and the true/false value...

    The case where the sum of the returned elements is not 100, due to rounding errors, doesn't need to be handled specially.

  • Custom User Avatar

    Hmm, the first paragraph makes me think about an elaborate algorithm to distribute the errors evenly over all numbers, and the second one crushes all these ideas... one could add a little complexity:

    Complete the method so that it converts a hash of values into integer percentages, where the individual percentages should be rounded to the nearest integer.

    If the total sum is not equal to 100 (due to rounding errors), it should return false, true otherwise.

    The method should take an optional set of keys as a second argument that allows only a subset of the hash values to be converted.

  • Loading more items...