3 is the number of temperatures. Similarly, for the test without temperatures, 0 is the number of temperatures. That number should not be included in the comparison. Please read the Input section of the statement for what the inputs consist of.
By the way, you may format your code properly by using </> button. And normally, the full/core code should not be posted on the forum, except for some of the easiest puzzle like this one.
Hello, could someone please check my solution, because I donât understand why the tests donât work with my solution. While when I test myself with the test values, everything works.
function abs(nb) {
if(nb == 0) return 0;
if(nb > 0) return nb;
if(nb < 0) return -nb;
}
if ( n == 0) {
console.log(n);
} else {
for(let i = 0; i < inputs.length; i++) {
if(i == 0){
min = inputs[i];
continue;
}
if(inputs[i] == min) {
continue;
}
if(abs(inputs[i]) < abs(min)) {
min = inputs[i];
continue;
}
if(abs(inputs[i]) == abs(min)) {
min = abs(inputs[i]);
continue;
}
}
console.log(min);
}
Think about a case where you have the same negative number twice in a row.
By the way you can format your code properly by using the </> button in the formatting toolbar. Except for a few Easy puzzles (including this one), it is better not to post the full/core code on the forum.
I suspect that the issue is actually that youâre not comparing numbers, youâre comparing strings.
In the default code, thereâs a line: const t = parseInt(inputs[i]);
But it seems that your code isnât making use of t, and instead uses inputs[i] directly, and theyâre still strings. A good fix is to use t instead of inputs[i] during the comparisons. Or, a quick fix to that line is:
Hi!
I work with java. I used arrays, for loop and if statements in my code.
I pass all the tests except I donât know how to check if no temperature is provided.
Any help?
Thanks
The first input is the number of temperatures. If it is zero, then no temperature is provided. (In case you miss it, a description of the inputs is included in the statement.)
so iâm using Rust: i get the smallest temp with using an if and comparing the read values against each other. For that i transform all temperature to a positive using the .abs() method. The problem i have now is that i am stuck and dont know how to display the coresponding negative number to my positive values