Ok ! got it thx
Instructions say:
Display 0 (zero) if no temperatures are provided. Otherwise, display the temperature closest to 0.
However, the test case for no temperatures is expecting no output, contrary to the instructions.
That case does expect an output of 0. Could you please copy and paste whatās shown in the console after you run that case?
Constraint is that the temperature set should contain between 0 and 10K temps => No test case is checking that and/or expecting value/error if set is too big (I truncated it)
Also noted that temps should be in a range between -276 and 5526 => No test case to check that and/or expecting value/error if a temp is out of range (I ignored those values)
Could be good to teach new developers to never trust user inputs
Tested in C.
Where do you see a case where the inputs violate the constraints/rules?
i placed the temps into a list and used an if statement to check if the length of the list is 0 and if this came back as true i set my answer to 0
after submitting your response they run your code through more test cases to make sure you didnāt hard code the solution
Hello !
Iāve got a bug with this puzzleā¦
Unit test 2 and 3 :
Testing with one value = max range.
Testing with one value = min range.
Are not displayed in the run test part during coding, but there are displayed after submissionā¦
So, I canāt reach 100% validationā¦
Any answer ?
I donāt quite understand your question, but yes, you do have to write a solution general enough to pass the hidden validators. This applies to all puzzles here, where most of the visible cases are different from the validators.
SECOND EDIT
@5DN1L sent me a link to an article that answered my confusion, so thanks! Itās because of the split function. The array of numbers is being created at the top with
var inputs = readline().split(' ');
Here is the article they sent me to explain the split function, for anyone else as confused as I was.
Split Function Explained
END SECOND EDIT
EDIT
I still donāt understand why my original code didnāt work, but I updated it so that the following code is at the bottom, and it passed all test cases this way.
if (!arr[0]) {
return 0;
}
!arr[0] is the same thing as arr.length === 0 is it not!? So irritating, lol.
END EDIT
I do not understand why my code did not pass the final test case (an empty array). The first thing my code checks for is an empty array, and returns 0 if itās the case. That is what the last test case is looking for, but it kept telling me āSaw ānothingā expected ā0āā.
The first block of code in my tempClosestToZero function is:
if (arr.length === 0) {
return 0;
}
I passed all of the other test cases, but failed the last one, and it is driving me crazy. Am I just overlooking some stupid detail, or is this a bug?
I code with JS by the way.
Did you just return 0 without console.log(0)?
No, I made a function that returns either 0 or the closest to zero, and then console logged a call to that function. The function was returning the answer for all of the other cases and those were passing, so returning 0 shouldnāt have failed.
If you want, you can send me your code in private message and Iāll take a look.
Edit: The issue has been found: JavaScript splitting an empty string does not result in an empty array of length 0.