Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

javascript - 这是我的考虑如何回答这个问题(this is my consideration how to answer this question)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...