Timeline for Count duplicates in a JavaScript array
Current License: CC BY-SA 4.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 10, 2020 at 13:24 | history | edited | CommunityBot |
Commonmark migration
|
|
Sep 4, 2018 at 21:01 | comment | added | Blindman67 |
@juvian The assumption is that the implementation of standard functions and data structures is optimal. Set is a hash table. On most JS engines it is implemented as such, same for Map . Using Object as a map and then for in on a object means that the object's prototype chain must be crawled (hence the is` hasOwnProperty`) There is no simple way to count the number of properties that an object has unless it is done as you create them.
|
|
Sep 4, 2018 at 20:31 | comment | added | juvian | You are relying on data structures (Set), access time and delete rely on the implementation (browser engine) it runs on. If set is implemented with a tree with O(log n) operations, then using object that is implemented with hash set would have lower time complexity. | |
Sep 4, 2018 at 20:29 | comment | added | Blindman67 | @juvian Time complexity is a measure of the algorithm independent of the device and language it is run on. | |
Sep 4, 2018 at 20:19 | comment | added | juvian | Both your time and space optimization rely on the engine it runs on. I fail to see how this is better in terms of time and space than original code | |
Sep 4, 2018 at 20:16 | comment | added | Blindman67 | @juvian The question asked for a review in terms of time and space, not performance. In JavaScript the best time complexity often does not result in the most performant code. If the metric was to be performance then there is plenty of room in the OP's code for improvement, depending on the engine it is run on. | |
Sep 4, 2018 at 19:35 | comment | added | juvian | I would recommend this if he was working with bigger ranges on the elements, but this is slower than his current solution for elements between 0 and 1000 | |
Sep 4, 2018 at 17:24 | vote | accept | Xameer | ||
Sep 4, 2018 at 16:28 | history | edited | Blindman67 | CC BY-SA 4.0 |
deleted 1204 characters in body
|
Sep 4, 2018 at 15:56 | history | undeleted | Blindman67 | ||
Sep 4, 2018 at 15:55 | history | edited | Blindman67 | CC BY-SA 4.0 |
deleted 1204 characters in body
|
Sep 4, 2018 at 15:52 | history | deleted | Blindman67 | via Vote | |
Sep 4, 2018 at 15:50 | history | answered | Blindman67 | CC BY-SA 4.0 |