I’ve inherited a codebase using multi-dimensional arrays (of sizes in the thousands) in a performance-critical path. In particular, the code wants to read off columns from the array and also perform element-wise addition by columns. I don’t really want to re-write a lot of logic to switch rows and columns just so I can use […]
Swift’s foundation library provides a sorted(by:) function for sorting arrays. The areInIncreasingOrder closure needs to return true if the closure’s arguments are increasing, false otherwise. How to use the closure for sorting by multiple criteria? Let’s take a look at an example of sorting an array of Player structs. Sort by score in descending order […]
The .reduce() method was also there in ES5, but I’d never used or seen someone using it in production at that time. Even today, I see people not aware of this method. I’ve also seen people only giving the same shopping cart example while explaining this method and, that’s why I think people don’t completely […]