Task Write a program to determine if a string contains all unique characters. Return True/true if it does and False/false otherwise.
The string may contain any of the 128 ASCII characters.
Specification hasUniqueChars(str) Parameters str: String - The string that may or may not contain all unique characters
Return Value Boolean - True if all characters in the string are unique
Examples str Return Value “abcdefg” true “abbcdefg” false
function hasUniqueChars(s) {
for(let i = 0; i < s.length; i++)
for(let j = i + 1; j < s.length; j++)
if (s[i] == s[j])
return false;
return true;
}
const {assert} = require('chai');
describe('hasUniqueChars()', () => {
it('Should return false', () => {
assert.isFalse(hasUniqueChars(" nAa"));
assert.isFalse(hasUniqueChars("++-"));
});
it('Should return true', () => {
assert.isTrue(hasUniqueChars("abcdef"));
});
});
|