使用 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