Hướng dẫn isogram javascript - biểu đồ javascript

Tệp này chứa văn bản unicode hai chiều có thể được giải thích hoặc biên dịch khác với những gì xuất hiện dưới đây. Để xem xét, hãy mở tệp trong một trình soạn thảo cho thấy các ký tự Unicode ẩn. Tìm hiểu thêm về các ký tự unicode hai chiều

// NHIỆM VỤ:
// Một isogram là một từ không có chữ cái lặp lại, liên tiếp hoặc không liên tiếp.
// Thực hiện một hàm xác định xem một chuỗi chỉ chứa các chữ cái
// là một isogram. Giả sử chuỗi trống là một isogram. Bỏ qua trường hợp thư.
functionisIsogram(str){isIsogram(str){ isIsogram(str) {
// Nếu trống trở lại đúng.
if(str.isEmpty){(str.isEmpty){ (str.isEmpty) {
returntrue;true; true;
}else{else{ else {
// Tất cả các trường hợp thường xuyên.
str=str.toLowerCase();=str.toLowerCase(); = str.toLowerCase();
}
// Chia chuỗi thành các ký tự riêng lẻ.
vararray=str.split('');array=str.split(''); array = str.split('');
varsortedArr=array.slice().sort();sortedArr=array.slice().sort(); sortedArr = array.slice().sort();
for(vari=0;i(vari=0;i (var i = 0; i < array.length; i++) {
// Nếu được tìm thấy sao chép lại FALSE.
if(sortedArr[i+1]==sortedArr[i]){(sortedArr[i+1]==sortedArr[i]){ (sortedArr[i + 1] == sortedArr[i]) {
returnfalse;false; false;
}
}
// Chia chuỗi thành các ký tự riêng lẻ.
returntrue;true; true;
}
//testing
// Chia chuỗi thành các ký tự riêng lẻ.('moOse'); //should return false
// Nếu được tìm thấy sao chép lại FALSE.('to be or not to be'); //should return false
// Chia chuỗi thành các ký tự riêng lẻ.('moOse');//should return false('wasdfgerty'); //should return true
// Nếu được tìm thấy sao chép lại FALSE.('to be or not to be');//should return false(); //should return true
// khác trả về đúng('wasdfgerty');//should return true

isisogram ('nai'); // sẽ trả về sai();//should return true

isisogram ('sẽ có hoặc không được'); // sẽ trả về sai

isIsogram( "Dermatoglyphics" ) == true
isIsogram( "aba" ) == false
isIsogram( "moOse" ) == false // -- ignore letter case

isisogram ('wasdfgerty'); // sẽ trả về true

function isIsogram(str){
var i, j;
str = str.toLowerCase();
for(i = 0; i < str.length; ++i) {
for(j = i + 1; j < str.length; ++j) {
if(str[i] === str[j]) {
return false;
}
}
}
return true;
}

isisogram (); // sẽ trả về đúng

function isIsogram(str){
var hash = {};
str = str.toLowerCase();
for (var i = 0; i < str.length; i++) {
if (hash[str[i]]) {
return false;
}
hash[str[i]] = true;
}
return true;
}

// đã vượt qua tất cả các thử nghiệm chạy.