← Back to challenges

Spin Around, Touch The Ground

JavaScriptHardarrayslanguage_fundamentals

Instructions

Given a list of directions to spin, "left" or "right", return an integer of how many full 360° rotations were made. Note that each word in the array counts as a 90° rotation in that direction.

Examples

spinAround(["right", "right", "right", "right", "left", "right"]) ➞ 1
# You spun right 4 times (90 * 4 = 360)
# You spun left once (360 - 90 = 270)
# But you spun right once more to make a full rotation (270 + 90 = 360)

spinAround(["left", "right", "left", "right"]) ➞ 0

spinAround(["right", "right", "right", "right", "right", "right", "right", "right"]) ➞ 2

spinAround(["left", "left", "left", "left"]) ➞ 1

Notes

  • Return a positive number.
  • All tests will only include the words "right" and "left".
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Peeling off the Outer Layers