Write a function. Test real cases. Improve your solution.
Parse an array of settings lines into [{key, value}, ...]. Trim each line; ignore blank lines and lines whose first non-whitespace character is #. Split a setting at its first equals sign, then trim the key and value. Ignore lines with no equals sign or an empty key. An empty value is valid, and later equals signs remain part of the value. For repeated case-sensitive keys, the last value wins while the key keeps its first valid appearance position. Do not interpret inline # characters as comments or convert value types. Leave the input unchanged.
[
[
" theme = dark ",
" retries=3 "
]
][
{
"key": "theme",
"value": "dark"
},
{
"key": "retries",
"value": "3"
}
][
[
" # export",
"",
" ",
"broken",
"=orphan",
" ok=yes"
]
][
{
"key": "ok",
"value": "yes"
}
][
[
"token=a=b==",
"url=https://example.test/?x=1"
]
][
{
"key": "token",
"value": "a=b=="
},
{
"key": "url",
"value": "https://example.test/?x=1"
}
][
[
"a=old",
"b=second",
"a=new"
]
][
{
"key": "a",
"value": "new"
},
{
"key": "b",
"value": "second"
}
][
[
"empty= ",
"color=#fff",
"note=keep # text"
]
][
{
"key": "empty",
"value": ""
},
{
"key": "color",
"value": "#fff"
},
{
"key": "note",
"value": "keep # text"
}
][
[
"__proto__=safe",
"Mode=on",
"mode=off",
"__proto__=still safe"
]
][
{
"key": "__proto__",
"value": "still safe"
},
{
"key": "Mode",
"value": "on"
},
{
"key": "mode",
"value": "off"
}
][ [] ]
[]
[
[
"10=first",
"2=second",
"10=updated"
]
][
{
"key": "10",
"value": "updated"
},
{
"key": "2",
"value": "second"
}
]Your code runs in your browser. These exercises use synchronous JavaScript functions and built-in data types; DOM access, network requests, and npm imports are unavailable. Runs stop after about four seconds. Test results support self-study and don’t certify proficiency.