javascript - 在 JavaScript 中按索引大小排序
问题描述
如何根据索引大小对字符串进行排序?
帮助排序的方法还是没有任何方法?
例如:
Input : sky is blue today
Output: is sky blue today
解决方案
您想按每个单词的长度排序吗?
var str = "sky is blue today"
console.log(
str.split(" ").sort(function(a, b) { return a.length - b.length; }).join(" ")
)
推荐阅读
- python - 在python 3中替换字符串中的单词
- javascript - 如何使用返回 json 的 api 请求从数组中拉出嵌套对象?
- swift - Swift:在 ViewController 中为私有函数创建单元测试
- sql - 结合两个根据结果对数据进行分类的查询
- key-value - 对于要存储 15.000.000 个整数键的 Berkeley DB,应使用哪种访问方法?
- java - Maven 没有像我预期的那样替换
- visual-studio - CordovaCall 插件不在 VisualStudio 上构建
- mysql - 在 MYSQL 中,我可以为任何人和每个人禁用删除表(或数据库)查询吗?
- javascript - 我可以在没有 root 的情况下看到的任何内部存储器文件夹的路径是什么?安卓工作室
- r - 在这种情况下如何处理丢失的数据?