Javascript - Sắp xếp tăng dần theo ký tự
Sắp xếp tăng dần theo ký tự
Viết chương trình JavaScript để chuyển đổi các ký tự của một chuỗi đã cho theo thứ tự bảng chữ cái.
Ví dụ:
Mã nguồn:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JavaScript program to convert the letters of a given string in alphabetical order.</title>
</head>
<script>
function alphabet_Soup(str) {
return str.split("").sort().join("");
}
document.write(alphabet_Soup("Python")+"</br>");
document.write(alphabet_Soup("Exercises")+"</br>");
</script>
<body>
</body>
</html>
Lưu đồ thuật toán: