EasyArraysNot started

Deduplicate article tags

An editor pasted a comma-separated tag list with repeats. Print every tag once, preserving the order in which it first appeared, and join the cleaned tags with | .

Input

One line of 1 to 30 lowercase tags separated by commas.

Output

One line: unique tags separated by | .

Example 1

Input

sql,data,joins,data,practice

Output

sql | data | joins | practice

The second data tag is removed and all first occurrences keep their positions.

Constraints

  • Each tag has 1 to 20 lowercase letters
  • At least one tag is present

Hints

Hint 1 of 3

split(',') creates the input array.

Hint 2 of 3

includes tells you whether the result already has a tag.

Hint 3 of 3

push only unseen tags, then join the result.

Solution

Show a reference solution and explanation
 JavaScript · reference solution
const tags = readline().split(',');
const unique = [];
for (const tag of tags) {
  if (!unique.includes(tag)) unique.push(tag);
}
console.log(unique.join(' | '));

Why it works

The left-to-right scan preserves the first occurrence naturally. A Set could also deduplicate, but the explicit array loop makes the membership decision and output order easy to follow.

Lesson for this exercise: JavaScript Arrays: Creating, Indexing and Changing Lists

Your program
const tags = readline().split(',');
const unique = [];
// keep only first occurrences
console.log(unique.join(' | '));

Tests: 3 cases including the examples. Passing every test marks the exercise solved in this browser.

Ready for a challenge?

How this page was checked. Every program on it was run with Node.js 22 at build time; runs in your browser in an isolated Web Worker by the publishing checks, and the output shown is what it printed. The Run buttons execute the same code on your device; nothing you type is sent anywhere.