DEV Community

Matt Ellen
Matt Ellen

Posted on

Turkey detector: awful answers only

It's turkey season in many places, especially for those of you in the United States of America.

And we all know what a turkey is, right? Yes, that's right. In ten pin bowling a turkey is when you get three strikes in a row.

I'm not sure why this time of year is dedicated to that, but there you have it. Traditions don't always make sense.

So, today's challenge is to find turkeys in people's bowling scores.

The function you write will need to take an array of arrays. The array will hold up to ten sub arrays. The first 9 sub arrays will always have 2 integers, from 0 to 10, and the 10th sub array will hold either 2 or 3 integers, from 0 to 10.

A strike for the first 9 sub arrays a strike is this sub array: [10,0].

For the 10th frame there can be up to 3 strikes:

  • single strikes: [10, 0, x], [x, 10-x, 10]
  • double strikes: [10, 10, x]
  • turkey: [10, 10, 10]

Where x is any integer from 0 to 9.


hasTurkey([[0,10],[1,5]]) //false
hasTurkey([[10,0],[10,0],[10,0]]) //true
hasTurkey([[10,0],[10,0],[0,10]]) //false
hasTurkey([[10,0],[10,0],[0,10],[9,1],[10,0]]) //false
hasTurkey([[0,10],[1,5],[2,1],[0,4],[8,1],[8,0],[10,0],[10,0],[10,0],[0,10,4]]) //true
hasTurkey([[0,10],[1,5],[2,1],[0,4],[8,1],[8,0],[10,0],[10,0],[9,1],[0,10,4]]) //false
hasTurkey([[0,10],[1,5],[2,1],[0,4],[8,1],[8,0],[1,0],[1,0],[10,0],[10,10,4]]) //true
Enter fullscreen mode Exit fullscreen mode

I want to see your worst implementations. Exponential time. Exponential space. Convoluted code. All of it. Roast the CPU like a turkey.

Discussion (0)