-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Feature Request: _.move() element in an array #1701
Comments
Thanks @blindstuff! This looks like a nice complement to the |
I created a repo with simple tests here and published |
As noted by @granteagon, this would be a nice touch for drag and drops :) |
Would it make more sense to just add a permutation function? Reorders arrays based on a permutation function or re-index array? Maybe a list of swaps to perform or what have you? const arr = [1, 2, 3, 4, 5]
_.permute(arr, [0, 2, 1, 3, 4]); // [1, 3, 2, 4, 5]
const fn = (idx) => idx + 1;
_.permute(arr, fn); // [_, 1, 2, 3, 4, 5] ? No matter what, questions are:
|
@c-dante I think undefined stuff should either raise an error or just insert undefined values. I like the permute idea, but a definite flaw I see is the array move is hand coded. If you were to use it in real code, wouldn't you still need to |
You can implement it in a few ways -- especially since you're creating a new array each time. Your implementation uses spread a bunch to reorder it, you could use the permute array to select elements, I'd avoid Yes, my example is hard coded, but there's no reason you the signature has to be that. Second example is a mapping function that goes from old to new index. Alternatively, you can have a vararg of swaps. _.permute(arr, newIndices);
_.permute(arr, ...swaps);
_.permute(arr, mapFn); are a few signiture ideas. |
I like the |
Interesting. That would still work for the drag n' drop examples above so I'm good. |
@c-dante et. al, I created a _.permute mixin on github and npm you can find here: https://github.com/granteagon/lodash-permute Feedback welcome! |
@c-dante |
Anyone, why |
Does this feature request still don't have enough likes? Whats the state? |
Using https://www.npmjs.com/package/lodash-move in the meantime but would love to see this in lodash officially! |
how many likes should we gather |
@stepovat There is no set number. Likes are used as an indicator of popularity of a request to help make API decisions as they come. |
_.permute is probably the better one to use if it does get added eventually. |
@jdalton This seems quite popular and have a mixin already, and still no joy? wow |
this would be useful and should be very simple to implement. also an api for |
@lyle45 agreed. Very useful for drag and drop. Just not sure that the bloat to the base library is necessary. To me, the question is how many different kinds of apps need these two bits of functionality. The only time I've required it is in implementing drag/drop on a list. I'm not sure there are greater than 10-15% of apps that have something like that. So I understand why it hasn't been added yet. It's a balancing act. I'm sure @jdalton is just guarding against excessive bloat. |
What we're wanting is the benefit knowing that lodash is the #1 function library and everything there is rock solid with no worries about the maintainer/bugs. With module loading in it adds zero bloat if you only load in what you need. Sure not everyone who uses lodash uses it (I'm sure it's a low adoption rate). It'd be great if lodash would be able to add in these functions that would even be helpful if 10-15% of it's users wanted it but would only be available for module loading. |
Would love to see it in #2020 |
I also, would enjoy this |
Bumping this again, 🤞 we get this in 2021 |
As Yoda says - Always hope, there is |
2021, nothing yet? Whoa, 5+ years and no work on this so far... |
Still looking for this feature to be implemented. Please loadash make a move. |
As drag and drop features using the help of array and objects are more on the boat, So this should be implemented |
I would love to see this. |
@jdalton: Landed on this issue after reading about "lodash style issue management" in the 11ty repo (here, specifically). I like the concept, but came here to see how it's working for you. Given that this issue (top-voted FR for several years) hasn't been acted on, does that mean you've given up on this practice? Would you recommend it for other projects? Any caveats or pitfalls to be aware of? |
shocked this hasn't made it yet |
This is a very important feature and it will actually be used in a lot of implementations. Still waiting.... :) |
Same here. Would love to see this feature. |
I'm waiting, too... |
Well... I have exactly that kind of thing to 'build', which is of course a no brainer, but thought 'oh well, maybe lodash...' and there is a request, many people, since 2015... come on guys, in what strange world would _.move or _.permute be bloating the library, when you have such things as _.isNull that brings 0 thing to the world 😄 |
It would be a very much handy function to have as a part of lodash... |
Hi, please forgive if "bump+1" comments on issues is the wrong kind of vote (per your docs), but am not sure given the radio silence - so I'm adding both. I also wanted to also thank you (the maintainers) and y'all(?) (the community) so damn much for creating and maintaining js' missing standard library, and pushing the js world further into the world of immutable fn-ish programming - I know I personally owe a lot of my love for that world (and transition into clojure prob lol) to lodash. |
move will be helpfull for slide component... tricky animation you know : / . |
The corona came and is almost gone and we are still waiting.. |
@jdalton How many reactions would be considered as popular? And if you see it as a popular request now, would be there any plan to implement this? |
+1 |
Seriosly, such a simple and usefull util func, and no feedback after 7 years? |
Still nothing? Its a really useful function |
Ha, just came here because I expected Lodash to have this function. Seems more useful than a lot of other Lodash methods. |
Oh wow really? I hardly understand how this can be overlooked |
I opened a PR here. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I remade another PR after the issues-bankruptcy here 🤞. |
I needed this in the implementation of a drag and drop gallery and found it was not on the lodash docs. If this already exists or is implemented in a different way I apologize as I could not find it.
A simple method to move an element inside of an array from one position to another.
Example usage
Solution taken from (and more detail / verifications needed available at):
http://stackoverflow.com/a/5306832/474883
The text was updated successfully, but these errors were encountered: