These are chat archives for ramda/ramda

10th
Dec 2018
Rakesh Pai
@rakeshpai
Dec 10 2018 10:22
@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
@rakeshpai
Dec 10 2018 10:28
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
@manniL
Dec 10 2018 10:29
@rakeshpai Indeed! Especially if you insert values in between it'll be expensive
Alexander Lichter
@manniL
Dec 10 2018 17:26
How can I express something like that elegantly?
obj.a += obj.b; return obj;
Asad Saeeduddin
@masaeedu
Dec 10 2018 20:56
@manniL if it's not necessary to have the mutation you could use: ({ a, b }) => ({ a: a + b, b })
Scott Sauyet
@CrossEye
Dec 10 2018 21:17
... or even ({a, b, ...rest}) => ({...rest, b, a: a + b})
Alexander Lichter
@manniL
Dec 10 2018 22:08
@masaeedu No, I don't want the mutation actually :)
And only have a and b as well as c and d in that case
so
obj.a += obj.b
obj.c += obj.d
return obj
@CrossEye I like that version :relaxed: Thanks!
Alexander Lichter
@manniL
Dec 10 2018 22:16
(And thanks to @masaeedu as well :+1: )