Code Monkey home page Code Monkey logo

Comments (21)

jdalton avatar jdalton commented on April 28, 2024

Naw (ok, ya I know it's weird I answered my own question :P)

It's totally edge and devs needing it can opt for something like _.shuffle(_.values(obj)).
Lo-Dash optimizes for the common case.

from lodash.

jdalton avatar jdalton commented on April 28, 2024

Shuffle was added to Underscore with the intent of being for arrays and only ran into objects because of its overuse/dependency on _.each.

See
jashkenas/underscore#71
and
jashkenas/underscore@f4cba51

from lodash.

jdalton avatar jdalton commented on April 28, 2024

Perf info:

Chrome 19:
Chrome 19 screenshot

IE 8:
IE 8 screenshot

iPhone iOS 3.1.3:
iPhone 3.1.3 screenshot

from lodash.

cowboy avatar cowboy commented on April 28, 2024

I'm REALLY not a big fan of doing "array" things on objects. Like the signature added to jQuery.map in 1.6:

http://api.jquery.com/jQuery.map/

from lodash.

jdalton avatar jdalton commented on April 28, 2024

I'm REALLY not a big fan of doing "array" things on objects. Like the signature added to jQuery.map in 1.6:

Ya, a lot of the time it just doesn't fit. I've moved methods like _.min, _.max, _.shuffle, _.sortBy and _.groupBy from "Collections" (objects and arrays) to "Arrays" to simplify each and optimize them for their common and tested/documented usage.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

IMHO, It depends on the philosophy behind Lo-Dash.
Since Lo-Dash supports custom build, it would be nice to have an equivalent drop-in replacement version and a lite or Lo-Dash-way version.
However this means Lo-Dash should maintain two versions of doc and src.

from lodash.

jdalton avatar jdalton commented on April 28, 2024

Since Lodash supports custom build, it would be nice to have an equivalent drop-in replacement version and a lite version.

As API's shift I have planned on making a lodash.underscore.js build.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

@jdalton So what's the core philosophy on Lo-Dash? Making it different from underscore.

from lodash.

jdalton avatar jdalton commented on April 28, 2024

@floydsoft

So what's the core philosophy on Lo-Dash? Making it different from Underscore.

Jeremy wrote:

The original idea with Underscore was to take the common set of useful data-manipulation primitives that you often need when working on a large JS application, and implement them in the fastest, smallest, and least invasive way possible -- so that if you need to just throw in Underscore into an existing application or web page to use a helper or two, it's never a problem to do so.

Unfortunately, Underscore has core design flaws that prevent it from being a simple drop-in utility and has since taken the stance to no longer concern itself with cross-browser consistency and close issues or revert patches instead of fixing real bugs.

As browsers progress the need for a lot of this API sugar will disappear because developers in ES5 compatible environments will use more native methods. So Underscore's BIG draw should be that it provides these features for older browsers in a consistent and cross-browser way. Its punt on consistency defeats a big reason to use it.

I started Lo-Dash with a focus on performance, consistency (in API and usage), and customizability. I wanted to show that it's possible to fix real issues like object iteration bugs in IE, Firefox, Opera, and Safari without sacrificing performance or adding mass bloat. I've taken it up a notch by providing custom builds, better documentation, and more debug helpers too.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

@jdalton

I started Lo-Dash with a focus on performance, consistency (in API and usage) and customizability.

Having consistency in mind, implicitly transmuting object to array wouldn't be a good design.

Therefore, moving shuffle's clients from Collections to Arrays is a proper change.

from lodash.

jdalton avatar jdalton commented on April 28, 2024

As of Lo-Dash v0.8.2 _.groupBy, _.max, _.min, _.shuffle, and _.sortBy work with objects.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

@jdalton interesting, why make the change?

from lodash.

jdalton avatar jdalton commented on April 28, 2024

@floydsoft I was able to find a way to keep the more common array usage fast while supporting objects for Underscore compat. The change was made so that the lodash underscore build removes all edge case compat issues.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

Could you share the tip you found ?

from lodash.

jdalton avatar jdalton commented on April 28, 2024

@floydsoft Here is an example of the fast path for _.max.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

@jdalton by length !== +length ? cool!

but why don't use length === undefined

from lodash.

jdalton avatar jdalton commented on April 28, 2024

@floydsoft To be consistent with how collections are detected.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

so why don't detect collections with length === undefined?

from lodash.

jdalton avatar jdalton commented on April 28, 2024

@floydsoft because making the check a bit more tight allows non numeric lengths to be avoided. A collection must a length that is a number primitive.

from lodash.

floydwch avatar floydwch commented on April 28, 2024

@jdalton ok, I've understood, thx!

from lodash.

lock avatar lock commented on April 28, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from lodash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.