I’ve finished this task and after running the tests I get all of them ok except for the last one:
X azSorted(["BB", "AA"])
returns false.
On the console I read:
azSorted([“BB”, “AA”]) returns false.
So the code is in fact giving the expected answer, but the test fails to pass.
Here’s the link of the challenge: https://learn.freecodecamp.org/coding-interview-prep/rosetta-code/compare-a-list-of-strings
And this is my code:
function allEqual (arr) {
// Good luck!
if (arr.length < 2){
return true;
}
let word = arr.pop();
return arr.every((element) => (element == word));
}function azSorted (arr) {
// Good luck!
let sorted = true;
let i = 1;
while ((sorted) && (i < arr.length)){
sorted = (arr[i-1] < arr[i]);
i++;
}
return sorted;
}console.log(azSorted([“BB”, “AA”]));
Can anyone check if this is correct or there is a bug that can be fixed?