en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

The solution to the task does not match its condition

Open Alexandre887 opened this issue 2 years ago • 3 comments

Function pow(x,n).

The task description says:

Write a function pow(x,n) that returns x in power n. Or, in other words, multiplies x by itself n times and returns the result. . . . P.S. In this task the function should support only natural values of n: integers up from 1.

The current check for a natural number in the task solution does not take into account the fact that the value passed in can be a fractional value greater than $\large1$. That is, if we pass in, for example, $\large1.1$ as $\large{n}$, the function will execute without any problems, even though $\large{1.1}$ is not a natural number.

This PR proposes an improved check that considers this nuance.

Alexandre887 avatar Jan 21 '23 23:01 Alexandre887

Unless the point of the exercise is to exclude fractional values right? For someone like me, I stuck to whole numbers when I did the exercise. I think it's worth clarifying the requirements of this specific task.

p2635 avatar Jan 28 '23 13:01 p2635

Unless the point of the exercise is to exclude fractional values right? For someone like me, I stuck to whole numbers when I did the exercise. I think it's worth clarifying the requirements of this specific task.

The description of the task must be consistent with the proposed solution. The author's solution does not take into account one nuance, which I described at the beginning of this PR. With the current code, the function can accept nonnatural numbers, even though the task says that it should only accept natural numbers.

There are two solutions to this problem:

  1. Accept my PR, which excludes the possibility of the function working with nonnatural numbers.
  2. Paraphrasing the task description, creating a different condition.

Alexandre887 avatar Jan 28 '23 13:01 Alexandre887

Agreed, I'm leaving that to the creator to decide on.

p2635 avatar Jan 28 '23 15:01 p2635