Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@24th-Dragon not exactly
I am not skipping the transformation, but skipping the element from the array at all (as if it wasn't there)
I am mapping a list of elements to a css grid in react
some elements might take more than one cell span, so when I transform one element to a cell that might occupy the space of the next element, when I am iterating the next element I cannot know what happened to the previous element.
One option *could be* use filter before, but I think a for loop is easier; I just move the index with the cell's span, and push to an array instead of returning; with that I was able to refactor my map to a for easily -
mr-user13525y@elvieeejo
You do not need to write a for-loop.
First do a "filter" on the list to get every data you want to transform and then do "transform" function. -
@elvieeejo @mr-user this is actually what I was just about to write, filter your list then map.
Might not be as performant, map, for each are about 80% slower than for loops* but much neater code.
* read an article once, can't remember where though :( -
I know, I already mentioned filter was a possible option in the comments, but for loop was easier to refactor to
Related Rants
Implementing a for loop in js because I need to skip some elements in a map as I transform. I'm feeling dirty
* cries in functional *
joke/meme
jokes
programming
react
functional
js