DEV Community

loading...

Discussion on: Daily Challenge #259 - Duplicate Encoder

Collapse
arthelon profile image
Daniel Hsing

TypeScript:

function isUnique(char: string, fullString: string): boolean {
  return fullString.indexOf(char) === fullString.lastIndexOf(char);
}

function duplicateEncoder(input: string): string {
  const lowercase = input.toLowerCase();
  return lowercase
    .split("")
    .map((char) => (isUnique(char, input) ? "(" : ")"))
    .join("");
}