MediumPro challengePythonJavaScriptTypeScript

Weak ETag Generator

Node.jsHTTPHashing

Generate a weak ETag from a string body: 'W/"<length>-<hash>"' where:

  • length is the body byte length (string length).
  • hash is a simple 32-bit FNV-1a hash, formatted as lowercase hex.

solve('hello') returns 'W/"5-4f9f2cab"'.

Sample tests

Test #1hello
Input: ["hello"]
Output: "W/\"5-4f9f2cab\""
Test #2Empty body
Input: [""]
Output: "W/\"0-811c9dc5\""
Test #3Single char a
Input: ["a"]
Output: "W/\"1-e40c292c\""
Test #4abc
Input: ["abc"]
Output: "W/\"3-1a47e90b\""
Test #5Hello World
Input: ["Hello, World!"]
Output: "W/\"13-5aecf734\""