Skip to content
大纲

将字符串按字母顺序排列 ​

语法 ​

js
import { alphabetical } from 'warbler-js';
const result = alphabetical(str);

参数 ​

  • str (String) : 需要按字母顺序排列的字符串 。

返回值 ​

String : 按字母顺序排列后的字符串。

源码 ​

js
const alphabetical = (str) =>
  str
    .split('')
    .sort((a, b) => a.localeCompare(b))
    .join('');

例子 ​

js
import { alphabetical } from 'warbler-js';
const initStr = 'adaskjdhaskjdhjkgrjheg';
const result = alphabetical(initStr);
console.log(result); //=> aaadddegghhhjjjjkkkrss

添加版本 ​

1.2.0

Released under the MIT License.