Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lololodash - 5 count the comments - bug #503

Closed
marklagendijk opened this issue Aug 22, 2014 · 3 comments
Closed

lololodash - 5 count the comments - bug #503

marklagendijk opened this issue Aug 22, 2014 · 3 comments

Comments

@marklagendijk
Copy link

In lololodash there is a bug in the 5th lesson. The following correct solution is not accepted:

// include the Lo-Dash library
var _ = require("lodash");

var worker = function(items){
    return _(items)
        .groupBy('username')
        .map(function(comments, username){
            return {
                username: username,
                comment_count: comments.length
            };
        })
        .sortBy(function(item){
            return item.comment_count * -1;
        })
        .value();
};

// export the worker function as a nodejs module
module.exports = worker;

The reason for this is that it expects the results to be sorted by comment_count, username, instead of just comment_count. So the following solution does work:

// include the Lo-Dash library
var _ = require("lodash");

var worker = function(items){
    return _(items)
        .groupBy('username')
        .map(function(comments, username){
            return {
                username: username,
                comment_count: comments.length
            };
        })
        .sortBy('username')
        .sortBy(function(item){
            return item.comment_count * -1;
        })
        .value();
};

// export the worker function as a nodejs module
module.exports = worker;
@finnp
Copy link
Member

finnp commented Aug 22, 2014

@mdunisch might help here :)

@mdunisch
Copy link

@marklagendijk

Thank you for that - you don't have to sort them by username. But you code make a different order to the last elements with the same count. I updated the exercise - so your first function would pass.

Just update lololodash with $> sudo npm install lololodash -g

@sudodoki
Copy link
Contributor

Considering this one closed. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants