【发布时间】:2017-04-24 18:04:30
【问题描述】:
- 我是 js 新手。
- 使用 charAt 我正在尝试编写一个代码,该代码应该将哪个单词显示为唯一字符。
- 我使用数组https://jsfiddle.net/at661zsu/实现了
- 但是如何使用 charAt 来实现。
- 在下面提供代码
//var wholeWord = "pak";
var wholeWord = "pakk";
for(i=0; i<wholeWord.length; i++) {
var firsLoopCharacter = wholeWord.charAt(i);
var unique = true;
for(j=0; j<wholeWord.length; j++) {
var secondLoopCharacter = wholeWord.charAt(j);
if( i === j)
{
continue;
}
if( firsLoopCharacter === secondLoopCharacter[j] ) {
unique = false;
break;
}
}
}
if (unique) {
console.log("its an unique string");
}
else {
console.log("not unique string");
}
【问题讨论】:
-
为什么需要使用 String::charAt ?
-
@GeorgeSimms 要求我不应该使用数组...你能在我的代码中更新...
标签: javascript jquery html string function