I won’t reveal where or when I got this question, but it always amused me. At the time, I answered it using Underscore and Coffeescript, which the interviewers allowed I was going to have access to… but here’s a pure ES6 solution.

The problem, simply stated, was “write a function that sums two polynomial equations and prints the results.” They defined the format for the input this way:

The interviewer just stared at it, and stared at it, and said, “I’ve never seen anyone solve that in three lines. Or that fast.”

I shrugged. “It’s a straightforward map/reduce of the relationship between exponents and coefficients, removing any factors that had a coefficient of zero. This seemed the least buggy way to do it. The riskiest part of this equation is the mapping back to string representation. The nice feature of this function is that if we generalize the first line over an arguments array, it works for any number of equations, not just two.”

He agreed. They ultimately didn’t hire me. I had a friend there, and he said, “They really liked you, but it was pretty clear you were already bored where you were and moving from one infrastructure job to another wasn’t going to change that.” Sad but true.