我的代码没有对字符进行排序。
我读过这方面的文章,看到了很多答案。我发现我可以使用sort()对字符进行排序,但是我不明白为什么它不起作用。
var string = readLine("Which letters do you want to sort?")
.toLowerCase()
.split(" ")
.sort();
print(string);发布于 2019-01-12 06:46:27
.split(" ")根据字符串中包含的每个空格对字符串进行拆分。如果它们之间没有空格分隔,则需要将其拆分为空字符串,这将分隔每个字符。将该行替换为.split(""),它应该可以工作。
发布于 2019-01-12 06:48:17
.split(" ")将按单词分隔字符串,并对这些单词进行排序,删除空格并对所有字符进行排序。
var string = readLine("Which letters do you want to sort?")
.toLowerCase() // Omit this line if you wan't to be case sensitive.
.split("")
.sort();
print(string); // [" ", " ", " ", " ", " ", " ", "?", "a", "c", "d", "e", "e", "h", "h", "i", "l", "n", "o", "o", "o", "o", "r", "r", "s", "s", "t", "t", "t", "t", "t", "u", "w", "w", "y"]发布于 2019-01-12 06:48:27
试试这个:
var string= "Which letters do you want to sort?"
.toLowerCase()
.split("")
.sort();
console.log(string);
https://stackoverflow.com/questions/54154986
复制相似问题