11:59
<lemmy>
Hi there. I have two small questions: First one is regarding a need I had recently to get both quotient and remainder of an integer division at the same time. Didn't found anything doing it in JS, and felt a bit dumb needing to perform two distinct operations to do so. Ok, it feels like micro optimization, and they are good chances that many JS engines optimize it transparently, but I just wanted to make sure I didn't missed anything about such a basic problematic 😛
12:05
<lemmy>
My second question is regarding a (maybe bad) code pattern I'm using often, which looks like : let options = {} ... options = { ... options, extraParam } ... options = { anotherExtraParam, ...options } ...
12:07
<lemmy>
This pattern is making me feel like I'm adding fields to an object as if one would do : count += 5 Except that there is no affectation operator to do it.
12:08
<lemmy>
Is there a better way to write it, that would avoid writing twice the 'options' variable in the first code example ?
12:12
<lemmy>
And would creating two new affectation operator such as : options ...= extraParam options =... anotherExtraParam Would make any sense. I mean I'm not even talking about all the syntaxique problematic it could arise, but simply if it would be of any use, wouldn't promote bad development habits, and wouldn't simply write another way something that could already be written in a simpler way 🤔
12:29
<lemmy>
Looking forward for any thoughts about it 😊
22:39
<Chris de Almeida>
lemmy: have you considered Object.assign() ?
22:42
<Chris de Almeida>
what you're doing with the spread operator is fine; doesn't seem like an anti-pattern at all to me, but I don't know what the rest of your code looks like 🙂
22:42
<lemmy>
Hey Chris de Almeida!
22:42
<lemmy>
Thanks for the feedback
22:43
<lemmy>
I'll have a look to Object.assign, thanks
22:54
<lemmy>
Yup, assign seems to do the trick, plus it can be used with an empty target object if immutability is needed. More functional oriented than operators, I prefer this way in fact :) thanks for the tip
23:28
<Chris de Almeida>
happy to help