1 Answers
Algorithm: Determine if all characters in a string are unique
To determine if all characters in a given string are unique, you can create an algorithm that iterates through each character in the string and checks if it appears more than once. Here is a sample algorithm:
function areAllCharactersUnique(str) { let charSet = new Set(); for (let char of str) { if (charSet.has(char)) { return false; } else { charSet.add(char); } } return true; } // Example usage const str = "abcdefg"; const result = areAllCharactersUnique(str); console.log(result); // Output: true
By using this algorithm, you can efficiently determine if all characters in a given string are unique.
Please login or Register to submit your answer