Underscore.js _.mod() Function
The _.mod() function returns the remainder of dividing the given dividend by the given divisor.
Syntax:
_.mod( dividend, divisor );
Parameters:
- dividend: given dividend from which mod is calculated.
- divisor: given divisor which is used to calculate the modulus.
Return Value: This method returns the calculated modulus from the given arguments.
Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed.
underscore.js contrib library can be installed using:
npm install underscore-contrib –save
Example 1: In this example, we will see the use of the _.mod() function
javascript
const _ = require( 'underscore-contrib' );
let mod = _.mod(24, 5);
console.log( "The Modulus is :" , mod);
|
Output:
The Modulus is : 4
Example 2: In this example, we will see the use of the _.mod() function
javascript
const _ = require( 'underscore-contrib' );
let mod = _.mod(120, 25);
console.log( "The Modulus is :" , mod);
|
Output:
The Modulus is : 20
Example 3: In this example, we will see the use of the _.mod() function
javascript
const _ = require( 'underscore-contrib' );
let mod = _.mod(12, 1);
console.log( "The Modulus is :" , mod);
|
Output:
The Modulus is : 0
Last Updated :
06 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...