Created
December 27, 2018 15:55
-
-
Save romarios1987/3c0bf48ee4ddd8f18a3f2d78d52099d5 to your computer and use it in GitHub Desktop.
Определите, содержит ли строка все уникальные символы
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function isUnique(str) { | |
var i, ch; | |
var len = str.length; | |
if (len > 127) { | |
return false; | |
} | |
for (i = 0; i < len; i++) { | |
ch = str[i]; | |
if (str.indexOf(ch, i + 1) > -1) { | |
return false; | |
} | |
} | |
return true; | |
} | |
console.log(isUnique('bar')); // true | |
console.log(isUnique('foo')); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment