Given a binary tree, return the id of the branch containing THE ONLY poisoned apple.
... then if we have a tree like this one:
apple (Node 2 True (Node 4 True Null Null) Null)
It should return Just 4 since it's the only branch containing just 1 poisoned apple. Yet your solution does not check for this nor there are tests cases like that:
apple (Node 2 True (Node 4 True Null Null) Null) `shouldBe` Just 4
How is this a suggestion?
Duplicate of many tree traversal katas.
No, the intention is that there can be at most one poisoned apple.
If I understand the description correctly...
... then if we have a tree like this one:
It should return
Just 4
since it's the only branch containing just 1 poisoned apple. Yet your solution does not check for this nor there are tests cases like that:This is still an issue, please fix it. Check Unnamed's post below.
Not a kata issue, you're mutating the input with pop, affecting the expected result. And remember to mark your post as having spoiler content.
just added a console log on top to see whats up...
const smallEnough = (a, l) => {
console.log(a , l);
return a.length ? a.pop() > l ? false : smallEnough(a,l) : true;
}
some of the random tests fail then for example:
Testing for 2
Log
[ 0, 8 ] 2
It should work for random inputs too - Expected: true, instead got: false
Are you sure that's the input of that test? The log appears above the expected result. Another problem could be you're mutating the input.
The random tests seem to be incorrect:
for input: [ 0, 3 ] 1
got: It should work for random inputs too - Expected: true, instead got: false
This comment is hidden because it contains spoiler information about the solution
Haskell translation
( You may get a "merge conflict" when approving. If so, I can fix that; let me know. It might also just work. )
Looks good to me.
id
s may be repeated, but I don't think anybody'll stumble over that.done
Loading more items...