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

new functionality #31

Closed
wants to merge 3 commits into from
Closed

new functionality #31

wants to merge 3 commits into from

Conversation

hrishikeshparanjape
Copy link

Added a method called foldLeft. Using this, we can facilitate developers to use curried arguments. For example,

[1,2,3,4,5].foldLeft(0)(function(init,next){init+next});//returns 15
["a","b","c","d","e"].foldLeft("")(function(init,next){init+next});//returns "abcde"

@ollym
Copy link
Owner

ollym commented Jul 13, 2012

@hrishikeshparanjape thanks for having a go at this. You've basically re-written the reduce method that was defined in the ECMA5 spec for javascript and is polyfixed in jstoolkit for platforms that don't support ECMA5 see here:
https://github.com/ollym/toolkit/blob/master/lib/array.js#L898-918

And so an example would be:

[1,2,3,4,5].reduce(function(sum, next) {
  sum += next;
}, 0); // returns 15

Its counterpart is reduceRight which is also polyfixed:
https://github.com/ollym/toolkit/blob/master/lib/array.js#L920-940

@ollym ollym closed this Jul 13, 2012
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.

None yet

2 participants