how functional is being able to do a copy of some ...
# suitescript
a
how functional is being able to do a copy of some types of variables with
=
and some not?
b
you are using Array.map strangely
Array.map is supposed to take an array and return a new one, with the elements transformed by the function in the callback
a
Why do you think I'm using map strangely?
b
your doesn't actually do any transforming
it just makes an array full of ["12345"] and undefined
The {"12345] is uniquely in there because the return value of an assignment is the value assigned
j
That's why I asked about side effects in your map function Your code is confusing because it uses map just to iterate over an array and set a value. forEach is more what you want
a
Map is widely use to modify the same array is iterating over in this case my Map is only modifying two matching properties...
j
Since map builds a new array, using it when you aren't using the returned array is an anti-pattern; use forEach or for-of instead. Signs you shouldn't be using map: A) You're not using the array it returns, and/or B) You're not returning a value from the callback.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#Description
b
If you wanted to, you could have done:
Copy code
oSearch.filters = 
oSearch.filters.map.......
it would have set the filters, but it would have been the wrong filters because your map function returns weird stuff
you also could have done:
Copy code
var filters = oSearch.filters;
filters.map ....
oSearch.filters = filters
i think that might have actually worked, but its an abomination
a
According to you what is an abomination?
b
using map instead of forEach
a
@battk Let me present to you the abomination...
b
those arent doing the same thing though
one is modifying an existing array, the other is creating a new one
the elements of arr will be doubled after the forEach example, the elements of arr will not be doubled in the map example
j
Yeah you can't compare those because they have different effects. See the link I posted
Since map builds a new array, using it when you aren't using the returned array is an anti-pattern; use forEach or for-of instead. Signs you shouldn't be using map: A) You're not using the array it returns, and/or B) You're not returning a value from the callback.
a
@battk I can recreate the example to do the same but I don't really have time for that... I think we have different perceptions, that is all... peace... ✌️
🤦 1
@jkabot This is very valid point I will consider for sure... Since map builds a new array, using it when you aren't using the returned array is an anti-pattern; use forEach or for-of instead. Signs you shouldn't be using map: A) You're not using the array it returns, and/or B) You're not returning a value from the callback.
b
message has been deleted
☝️ 1
👍 1
👏 1