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

some additional features / convenience funcs #441

Closed
wants to merge 1 commit into from

Conversation

AndreasBriese
Copy link

Hi,
i added _.sum() _.mean() _.median() to collections section and nrange() to arrays. tests are adjusted appropriately.
in further detail:
_.sum(obj): returns the sum of the elements objects.
_.mean(obj): returns the mean of the elements in the object.
_.median(obj): returns the median element (middle in sorted). works also with string / char elements (i.e. to split lists of names by alphabet)
_.nrange(n) adds convenience functions to _.range(n):
nrange(-3) -> [0, -1, -2];
nrange(0,3) -> [0, 1, 2];
nrnage(3,0) -> [3, 2, 1];
(might replace _.range(n) to reduce redundance)
do{}while() instead of while(){} speeds up the script slightly on FF4+ and Safari.

test suite and speed test is adjusted and tests passed.

Andreas

@jashkenas
Copy link
Owner

Lovely stuff, but I'm afraid that it's a bit out of scope for core Underscore.js functions. I'd love it if you could wrap it up as an _.mixin plugin, and add a link in the Wiki.

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

Successfully merging this pull request may close these issues.

2 participants