Main Page
 The gatekeeper of reality is
 quantified imagination.

Stay notified when site changes by adding your email address:

Your Email:

Bookmark and Share
Email Notification
jsDuplicateCharFilter [Go Back]
The purpose of this page is to show how to remove sequential, duplicated characters in a string.

You may have noticed that a growing number of companies will "test" individuals to gauge programming proficiency. What is interesting, now that a few waves of people coming up with "tests" have come and gone, the "test" questions have grown more abstract and removed from business and real-world practicality. For example, consider this "test" question: Remove all sequential duplicated characters in a string. A simple solution is shown below.

/* Remove back-to-back duplicate characters from string as those repeating characters should be ignored */
var txtCharIterationPosition = 0;
var s = "abccdeef"; // String input
var sCleaned = ""; // After filtering, sCleaned will have a value of "abcdef"

while (parsed === 0) {
if (txtCharIterationPosition > s.length) { parsed = 1; }
else {
var nextChar = "";
var currentChar = s.charAt(txtCharIterationPosition);
if (sCleaned.length === 0) { sCleaned = currentChar; }
if (s.charAt(txtCharIterationPosition + 1)) { nextChar = s.charAt(txtCharIterationPosition + 1); }
if (currentChar !== nextChar && nextChar.length === 1) { sCleaned = sCleaned + nextChar; }

Off hand, I cannot imagine a single situation something like the above would be needed (what if a string contained the valid word "suggested", for example). In today's world, with fast evolving technology, 3rd party libraries and other tools (like the IDE) a person is more likely to use an already-built solution (such as searching for one under Knowledge In Time (KIT)*, or leverage an IDE's capability) rather than know all the intimate low-level details of a particular language and functions. A trivial comparison case is that Php has over 1000 built-in functions by itself - will someone coming in for a "test" know all of those in order to effectively prep for an abstract question?

* Knowledge In Time (KIT) is a term that I came up with that is similar to Just In Time (JIT) used in supply management. With most of our lives now exposed to the Internet, if anyone wonders how to do something they search the Internet under the premise of Knowledge In Time (KIT) for the information they need, at the time it is needed rather than attempting to stockpile and manage vast quantities of knowledge just "in case" it may be needed.

About Joe