The map() method creates a new array with the results of calling a provided function on every element #1347
Replies: 8 comments
-
Posted at 2019-12-09 by AkosLukacs
Keep in mind that this allocates a new array every time. Easier to reason about IMO, but don't allocate a lot, if you are low on memory. And of course you can do it in a one-liner:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-12-09 by @MaBecker That was quick - Thanks , I prefer the one-liner ;-)
Else you modify array p[] , or am I missing something here? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-12-09 by AkosLukacs Yes, foreach, for loop modifies the array in place (ok, you can create a new array, but usually you don't). Just console.log out after each call to compare the different ways. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-12-09 by @allObjects ...instead of using terniary if-then-else construct and or modulo Nice to use |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-12-10 by @MaBecker I guess this is even quicker than module, thanks 😊 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-12-10 by @gfwilliams Right now, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-12-10 by @MaBecker Multiple arrays to draw more than one Poly with a single call would be nice too. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-12-10 by @allObjects I know why leaving out the array completely is not on the list: limit of number of arguments... On the other hand to have extra packaging around the data is like going to produce store and find every cherry in it's own package even though many being twins or triplets by stem... ;-). With scares resources I'm totally fine with single level array packaging... for simple polygons though I could well live w/ just plain 'naked' arguments. For places where that is so - such as the rectangle - I still can do it data driven w/ single 'object' by usine For polygon I could see the close information being in the last array element... But thinking about why I would like to have that and how I would use and construct it, it is not worth further pursuit (to go o-o for shapes, the shape info would be missed and needed as well to be included... For that I can then either make a real object w/ properties, such as: shape:, vertices:, closed:, or with arrays as object crutches, [shapeTypeValue,[verticesValues,...],closedValue]. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-12-09 by @MaBecker
Hi,
can p.map() be used to translate, scale or rotate points in an array with the corresponding function?
For now I use something like this, but prefer to use . map.
Any suggestion how to use .map to do the job?
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions