使用 JavaScript 对字符串进行按字母顺序排序并插入下划线
问题
我们需要编写一个 JavaScript 函数来接收一个字符串数组。
我们的函数应按照字母顺序对数组中的字符串进行排序,并且该字符串的每个字符都应由“***”隔开。
示例
以下是代码 −
const arr = ['this', 'is', 'some', 'string', 'array'];
const specialSort = (arr = '') => {
const copy = arr.slice();
copy.sort();
const el = copy[0];
const res = el
.split('')
.join('***');
return res;
};
console.log(specialSort(arr));输出
a***r***r***a***y
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP