← Back to challenges

Western Showdown

JavaScriptHardstringsconditions

Instructions

Wild Roger is participating in a Western Showdown, meaning he has to draw (pull out and shoot) his gun faster than his opponent in a gun standoff.

Given two strings,p1 and p2, return which person drew their gun the fastest. If both are drawn at the same time, return "tie".

Examples

showdown(
  "   Bang!        ",
  "        Bang!   "
) ➞ "p1"

// p1 draws his gun sooner than p2

showdown(
  "               Bang! ",
  "             Bang!   "
) ➞ "p2"

showdown(
  "     Bang!   ",
  "     Bang!   "
) ➞ "tie"

Notes

Both strings are the same length.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Convert Number to Corresponding Month Name