Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created October 3, 2017 20:59
Show Gist options
  • Save unilecs/40e43789eb9c3106c1b3fb3c85d84262 to your computer and use it in GitHub Desktop.
Save unilecs/40e43789eb9c3106c1b3fb3c85d84262 to your computer and use it in GitHub Desktop.
Check that all symbols are unique in the string
function checkUniqueSymbols(inputStr) {
if (inputStr) {
const hasDuplicateSymbols = inputStr.match(/(\w)(.+)?\1/) !== null;
return !hasDuplicateSymbols;
}
return false;
}
console.info("abcadez", checkUniqueSymbols("abcadez")); // false
console.info("abcdefg", checkUniqueSymbols("abcdefg")); // true
console.info(" try ", checkUniqueSymbols(" try ")); // true
console.info(" ", checkUniqueSymbols(" ")); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment