Let's look at underscore's "sample" method, which produces some amazing surprises if you poke at it a little.
Produce a random sample from the list. Pass a number to return n random elements from the list. Otherwise a single random item will be returned.
Easy enough?
I can't fit the answer in a tweet because there are too many cases.
e.g., _.sample(a, 1) is slower than _.sample(a)
The function is never time-efficient (a 1,000-element array is entirely shuffled to pluck two values).
Again, depends on how it's called. For n != undefined, the array is always copied in its entirety (!!!) even if only sampling a small # of elements (isn't this the intended use case?)
_.sample({ height: "10", width: "10", length: "10" }) is "10"
_.sample({ height: 10, width: 10, length: 10 }) is undefined
_.sample({ height: 10, width: 10, length: 10 }, 1) throws "sample.slice is not a function"
_.sample(2, [3, 4]) returns [], but _.sample(2) returns undefined
[1, 2, 3].map(_.sample.bind(_, [3, 4, 5]) returns something like [[5], 3, 4] - have fun explaining that one
_.sample("abcdef") returns a random character, as expected
_.sample("abcdef", 3) is *always* "abc"
_.sample("abc", "abc") is ""
Underscore was built for size, not speed/predictability, but it's still *incredibly* hard just to describe the behavior of this function. I only tweet about TypeScript, though, so what's the connection?
1) Figure out all the rules the docs don't explain
2) Get people to agree on which of those behaviors constitute "errors"
3) Explain that behavior to a computer using a general-purpose DSL