Skip to content
DevFlash

Junior

Normalize and dedupe tags

A pure TypeScript function with the edge cases an interviewer will poke at.

FreeJunior~15 min

This challenge is under editorial review.

Why it shows up in interviews

Data cleanup is the most common warm-up in coding tests because it has no framework to hide behind. The question is simple; the edges are not: spaces inside the tag, an empty string, the same tag typed twice with different casing.

Reviewers look at the order of operations (normalize before checking for duplicates), at whether the input array stays intact, and at whether you can state the time and memory cost of your approach without being asked.

What you will build

  1. Trim and lowercase every tag.
  2. Collapse inner whitespace into a single dash.
  3. Drop empty entries.
  4. Remove duplicates, keeping the order of first appearance.
  5. Do not mutate the input.

Out of scope: Unicode normalization (accents stay as typed).

How you will be graded

Passing the tests is the start. In the follow-up conversation, a good explanation covers:

  • Explains why normalization happens before the duplicate check.
  • Mentions the cost of the approach (time and memory).
  • Says how the input stays untouched.

Starter code

/src/normalize-tags.ts

/**
* Recebe tags digitadas por pessoas e devolve uma lista limpa.
*/
export function normalizeTags(input: string[]): string[] {
// implemente aqui
return input;
}
See the tests that will run /src/normalize-tags.test.ts
import { normalizeTags } from "./normalize-tags";
describe("normalizeTags", () => {
it("lowercases and trims each tag", () => {
expect(normalizeTags([" React ", "TypeScript"])).toEqual(["react", "typescript"]);
});
it("removes duplicates after normalizing", () => {
expect(normalizeTags(["react", "React", " react "])).toEqual(["react"]);
});
it("keeps the order of first appearance", () => {
expect(normalizeTags(["zod", "react", "ZOD", "css"])).toEqual(["zod", "react", "css"]);
});
it("turns inner whitespace into a single dash", () => {
expect(normalizeTags(["state management"])).toEqual(["state-management"]);
});
it("drops empty and whitespace-only entries", () => {
expect(normalizeTags(["", " ", "hooks"])).toEqual(["hooks"]);
});
it("does not mutate the input array", () => {
const input = [" A ", "a"];
normalizeTags(input);
expect(input).toEqual([" A ", "a"]);
});
});

Hints

Open only if you get stuck. Each one gives away a little more.

Hint 1

Normalize first, compare later. Two tags are duplicates only after trim and lowercase.

Hint 2

A Set answers "have I seen this?" in constant time, but a Set alone does not decide the output order.

References