by nmjohn · 10y ago · 0 comments
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 - remainderNo comments yet.