GitHub 6248★

Calculate the mod of collection index

JavaScript version

const mod = (a, b) => ((a % b) + b) % b;

TypeScript version

const mod = (a: number, b: number): number => ((a % b) + b) % b;

Examples

mod(-1, 5); // 4
mod(3, 5); // 3
mod(6, 5); // 1
Follow me on and to get more useful contents.