Comments (9)
The order is not guaranteed as few things can happen. If order is important then either it is sorted and returned, or it is returned in the order it was passed.
from dollar.
it is returned in the order it was passed.
This is what I would expect to happen but that doesn't currently happen.
Order isn't kept for $.uniq
but other methods such as $.compact
do return things in the order they are passed. So I guess I was expecting $.uniq
to do the same.
If you think $.uniq
shouldn't keep the order then this issue becomes a feature request for a method that provides $.uniq
returning items in the same order they were provided.
from dollar.
Also thanks for a great library. It covers off so many things that should be standard in Swift.
from dollar.
Yes adding it as an option makes sense as underneath it is using dictionary keys and returning that which are uniq but the order is ignored for speed.
from dollar.
Now the other thing to figure out is what is the order if there are duplicate values as such [Stockholm, SE, Stockholm]
from dollar.
Should it be [Stockholm, SE] or [SE, Stockholm]. The question is should we pick the last uniq value and its order or pick the first and use that order.
from dollar.
I think [Stockholm, SE]
. It makes sense to me to iterate through the array in order, accepting return values if they are unique and then discarding anything that comes up that isn't uniq.
So $.uniq([1,2,3,1,4])
outputs [1,2,3,4]
You were talking about performance which is great. Would the optional be something like this:
$.uniq([1,2,3,1,4], preserveOrder: true)
The question is would order preservation be turned on or off by default? I'd be interested to know what you think, but my opinion is it would be better to keep Dollar.swift
accurate by default, not tripping people up but have the option of disabling order preservation for speed.
Array
's in Swift by default preserve order and so this is why I raised this issue because I ran my array through $.uniq
and suddenly it was not in order!
Are there other instances where you've had to decide on speed vs accuracy? If so which did you pick?
from dollar.
Thanks heaps @ankurp!
from dollar.
No problem.
from dollar.
Related Issues (20)
- Latest version doesn't work with Carthage HOT 2
- Update README/docs
- Add function for swapping elements in collection HOT 1
- Tag a release for Linux support HOT 7
- Why support only 10.1 as minimum deployment target? HOT 10
- How do you use this with Cordova swift projects? HOT 1
- multi-dimensional array flatten(my wrong)
- Swift 3.1 compatibility HOT 2
- Difference with iterator HOT 2
- Implement debounce HOT 4
- Where's String#strip()? HOT 4
- Swift 4 support
- I am getting $ is not identifier issue in XCode HOT 1
- Proposal: Array's fullfill function HOT 1
- Project Warnings: Use 'compactMap' Instead Of 'flatMap' HOT 1
- Update!!!!!!!! HOT 5
- Swift 5 support HOT 1
- Distribute to test flight failed with Carthage
- Question: Why would you not want to extend built-in objects?
- Update Package.swift to Support Swift Package Manager HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dollar.