These are chat archives for ramda/ramda

Dec 2018
Rakesh Pai
Dec 10 2018 10:22 UTC
@manniL Same here. :) After 2 hours, I started hunting for an alternative solution, just in case it doesn't complete. It's still running even now, over 24 hours later. :)
Rakesh Pai
Dec 10 2018 10:28 UTC
Learnt a lot though. Appending to arrays can be really expensive, in spurts. Most JS engines (v8 for eg.) will grow the array size in batches. So, if you keep appending to an array, at certain points, it looks like v8 will have to reallocate new contiguous memory for the array, and copy over the old values to the new location. So, every once in a while, .push-ing to an array will be O(n), where you'd expect it to be O(1).
Since this happens for large arrays, n is usually large when it hits you with the O(n) operation, making things extra slow when you need the perf.
Alexander Lichter
Dec 10 2018 10:29 UTC
@rakeshpai Indeed! Especially if you insert values in between it'll be expensive
Alexander Lichter
Dec 10 2018 17:26 UTC
How can I express something like that elegantly?
obj.a += obj.b; return obj;
Asad Saeeduddin
Dec 10 2018 20:56 UTC
@manniL if it's not necessary to have the mutation you could use: ({ a, b }) => ({ a: a + b, b })
Scott Sauyet
Dec 10 2018 21:17 UTC
... or even ({a, b,}) => ({, b, a: a + b})
Alexander Lichter
Dec 10 2018 22:08 UTC
@masaeedu No, I don't want the mutation actually :)
And only have a and b as well as c and d in that case
obj.a += obj.b
obj.c += obj.d
return obj
@CrossEye I like that version :relaxed: Thanks!
Alexander Lichter
Dec 10 2018 22:16 UTC
(And thanks to @masaeedu as well :+1: )