3 ms·
I don't think the problem is the modulo operator per say, but rather programming in general is incredibly vast and even very experienced programmers will not ha
by nmjohn 10y ago
I don't think the problem is the modulo operator per say, but rather programming in general is incredibly vast and even very experienced programmers will not have encountered some thing X which many other developers consider to be absolutely trivial.
For example with modulo, I feel like I use it quite often, relatively speaking. Somewhat contrived example of usage on the web side of things:
Let's say you're building a grid system that will have an unknown number of items. The grid is 12 columns wide. In the last row, any items that otherwise would be empty should instead have a placeholder item displayed.
Given an arbitrary array of items, how many additional placeholder items should be included in what gets rendered?
const colWidth = 12
const remainder = items.length % colWidth
const numPlaceholders = (remainder === 0) ? 0 : colWidth - remainder