I have no idea how to solve this Question I want to use RECURSION for this(我不知道如何解决这个问题,我想为此使用RECURSION)
I would appreciate it if you answer for me ...
(如果您为我回答,我将不胜感激。)
Question(题)
- Write a function called "modulo".
(编写一个称为“模”的函数。)
Given 2 numbers, "modulo" returns the remainder after dividing num1 by num2
(给定2个数字,“取模”将num1除以num2后返回余数)
Notes:
(笔记:)
Do NOT
use the actual built-in modulo (aka "remainder") operator (%)
in your implementation.
(Do NOT
使用实际的内置模(也称为“余数”) operator (%)
。)
- Modulo always returns the sign of the first number.
(模数总是返回第一个数字的符号。)
output(输出)
let output = modulo(25, 4);
console.log(output); // --> 1
My code(我的密码)
function modulo(num1, num2) {
// termination
if (num1 - num2 === 0 ) {
return 0;
}
// base
if (num1 - num2 === 1 ) {
return 1;
}
// RECURSION
return modulo(num1,num2)
}
ask by JJ_strong translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…