An HTML sanitizer reads inline style attributes like color: red; margin: 0 4px and checks each declaration.
Write splitStyle(style) that returns a list of [property, value] pairs in order. Declarations are separated by ;. Split each one at its first :. Trim spaces around the property and the value, and lowercase the property.
Skip a declaration if it has no :, or if its property or value is empty after trimming. Values never contain ;, but they may contain : (as in a URL).
Input: style = "color: red; margin: 0 4px" Output: [["color","red"],["margin","0 4px"]]
Two declarations; spaces around each part are trimmed.
Input: style = "Background: url(https://x.dev/a.png);;" Output: [["background","url(https://x.dev/a.png)"]]
Only the first : splits; the empty declarations are skipped.
0 <= style.length <= 10^4Run 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 #626 Split a Style Attribute. 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.