Skip to main content

Timeline for Sort by Multiplying

Current License: CC BY-SA 3.0

14 events
when toggle format what by license comment
Feb 19, 2022 at 16:18 comment added l4m2 Can you a=>a.map(p=n=>p=n*-~(p/n)) instead?
Feb 11, 2016 at 22:12 comment added edc65 @PatrickRoberts sorry for the late answer ... that fails for an array with just 1 element
Feb 10, 2016 at 20:32 comment added Patrick Roberts @edc65 if you want to keep your algorithm and save 4 bytes, then use a=>a.map(n=>a=n*-~(a/n))!
Feb 10, 2016 at 20:19 comment added edc65 @PatrickRoberts thinking again, I could still avoid globals: f=a=>a.map(n=>a+=n-a%n,a=0). But it's not my algorithm (silly me) so I'll keep mine as is and upvote aross
Feb 10, 2016 at 18:02 comment added Patrick Roberts @edc65 I hate to make you revert to a global variable, but you can save 3 bytes by changing your function to a=>a.map(n=>p+=n-p%n,p=0) as @aross suggested.
Feb 10, 2016 at 17:51 comment added Patrick Roberts @edc65 glad you liked my parameter format. Just pointing out that by "neat" I did not mean shorter.
Feb 10, 2016 at 17:49 comment added edc65 @PatrickRoberts can be neat but is longer. The p as a parameter is a nice idea, I'm using it
Feb 10, 2016 at 17:48 history edited edc65 CC BY-SA 3.0
added 136 characters in body
Feb 10, 2016 at 17:24 comment added Patrick Roberts A neat way to do this using ES7 generator comprehensions is (a,p)=>[for(n of a)p=n*-~(p/n)]
Feb 9, 2016 at 17:52 comment added Charlie Wynn @edc65 sure enough, p is already defined on this page!
Feb 9, 2016 at 17:47 comment added edc65 @CharlieWynn if you don't initialize a variable you get the error for undefined variable. If by chance the variable already exists (that could easily happen in the environment of a web page), it could have any wrong value.
Feb 9, 2016 at 16:34 comment added Charlie Wynn Can't you skip the p=0? You need it to run it multiple on multiple lists but the question is just for a single list
Feb 9, 2016 at 16:31 comment added aross I think you can save a few bytes by using modulo, just like I did in my answer.
Feb 9, 2016 at 12:00 history answered edc65 CC BY-SA 3.0