isMultipleOf method

bool isMultipleOf(
  1. int other
)

Returns true if this int is a multiple of other

Example:

10.isMultipleOf(5); // true
11.isMultipleOf(5); // false
0.isMultipleOf(5);  // true (0 is a multiple of any number)

Throws:

  • ArgumentError: If other is zero

Implementation

bool isMultipleOf(int other) {
  if (other == 0) {
    throw ArgumentError('Cannot check if a number is a multiple of zero');
  }
  return this % other == 0;
}