6 kyu

Simplify Unique

Description:

Things like blog posts and CMS pages have titles. But they're accessed through urls. Titles can have old character in them. They can even be exactly the same as another one. So the back-end has to simplify those titles to be valid for a url at all, while still making sure they stay unique.

Write the function simunq (catchy, right?) so that it converts the given original string and returns it with all the weird, disallowed characters replaced by a "wildcard."

Here, the allowed characters are all english lowercase and uppercase characters, all digits, the space character, and the wildcard... the wildcard being a dash -.

simunq("blah?") == "blah-";

But at the same time, two urls must never overlap. So if it's the same as an already-used simunq string, tag a -n to the end of it, n being the number of identical strings that came before it, plus 1 for the current string.

simunq("blah") == "blah";
simunq("blah") == "blah-2";
simunq("blah-2") == "blah-2-2";

And, just so we can test a little easier, add a reset method to the simunq function. After this has been called, all the previously created simunq strings should be ignored.

simunq("string") == "string";
simunq("string") == "string-2";
simunq.reset();
simunq("string") == "string";

Have fun~!

Algorithms

Stats:

CreatedNov 7, 2016
PublishedNov 7, 2016
Warriors Trained209
Total Skips11
Total Code Submissions722
Total Times Completed85
JavaScript Completions85
Total Stars8
% of votes with a positive feedback rating85% of 37
Total "Very Satisfied" Votes28
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes2
Total Rank Assessments7
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • wthit56 Avatar
  • Voile Avatar
  • ZED.CWT Avatar
Ad