MediumPro challengePythonJavaScriptTypeScript

Normalize HTTP Headers

Node.jsHTTP

Normalize header names to lowercase. If a header appears multiple times,
join its values with ', ' (in original order).

solve([['Content-Type', 'text/html'], ['Set-Cookie', 'a=1'], ['set-cookie', 'b=2']])
{ 'content-type': 'text/html', 'set-cookie': 'a=1, b=2' }.

Sample tests

Test #1Single
Input: [[["Content-Type","text/html"]]]
Output: {"content-type":"text/html"}
Test #2Combine duplicates
Input: [[["Set-Cookie","a=1"],["set-cookie","b=2"]]]
Output: {"set-cookie":"a=1, b=2"}
Test #3Empty
Input: [[]]
Output: {}
Test #4Two distinct
Input: [[["X-A","1"],["X-B","2"]]]
Output: {"x-a":"1","x-b":"2"}
Test #5Three duplicates
Input: [[["Accept","a"],["ACCEPT","b"],["accept","c"]]]
Output: {"accept":"a, b, c"}