Trying to create a function to check for a tall number (i.e., every digit is less than or equal to the digit to its right, such as 123, 059, etc.).
Following code is the issue:
const n = parseInt(readline());
if (n.toString().length === 1)
console.log('true');
else
{
var z = n.toString().split('');
console.log(z.reduce((a, b) => b > a));
}
This test fails: 01223047 (returns true when it should return false).
It worked on numerous other tests, but not this value. Shouldn't reduce be testing each pair and returning true/false? If there's one false, it should return false, correct? Am I using reduce incorrectly? Is there another function I could use to shorthand this test instead of writing a loop?
01223047is337447as an integer, you need to havenas a string and parse them to an int in your reduce functionreadlineonly to then repeatedly convert it back to a string... It's particularly odd if one of your examples has a leading digit "0" as doing that removes the leading digit.