Skip to main content

Article archive %1

Reduce nested loops with closures and functional programming

2021-05-12
Today I was developing some code that combined information from 2 different arrays. The first array was a list of data-objects. Each data-object has a 'type' parameter. The second array was a list of 'types' and it function is to specify the order (sorting) and which data-object must be rendered. Initially I solved this with 2 nested foreach loops, which hurts the eyes and can be a performance killer when working with big data-structures. So in a code-review my collegue asked me to rewrite this.