A browser console panel keeps the level of every message it has printed, oldest first, in levels. Each level is one of the strings "info", "warn", or "error", but some tools also log odd levels such as "Error".
Write lastError(levels) that returns the index of the most recent message whose level is exactly "error" (lowercase), or -1 if there is none.
Input: levels = ["info","error","warn","error","info"] Output: 3
Errors are at 1 and 3. The most recent one is at index 3.
Input: levels = ["info","warn"] Output: -1
No message is an error.
0 <= levels.length <= 10000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #153 Last Error in the Console. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.