How to find the remainder without using modulo operator in Node.js

2 Answers

0 votes
const n = 29;
const divisor = 6;
       
let remainder = n;
   
while (remainder >= divisor) {
       remainder = remainder - divisor;
}
   
console.log("The remainder is: " + remainder);
 
   
   
   
   
/*
run:
   
The remainder is: 5
   
*/

 



answered May 18, 2022 by avibootz
0 votes
const n = 29;
const divisor = 6;
       
const remainder = n - divisor * parseInt(n / divisor);
   
console.log("The remainder is: " + remainder);
 
   
   
   
   
/*
run:
   
The remainder is: 5
   
*/

 



answered May 18, 2022 by avibootz

Related questions

2 answers 214 views
2 answers 190 views
2 answers 246 views
2 answers 194 views
2 answers 174 views
...