按照camelCase属性的排名规则
创始人
2024-08-23 13:00:41
0

在JavaScript中,我们可以使用以下代码实现camelCase属性的排名规则:

let orderByCamelCase = function (a, b) { const regex = /([A-Z])/g; const ax = [], bx = [];

a.replace(regex, function(m, $1) { return "-" + $1.toLowerCase(); }).split('-').forEach(function(v) { ax.push(isNaN(parseFloat(v)) ? v : parseFloat(v)) }); b.replace(regex, function(m, $1) { return "-" + $1.toLowerCase(); }).split('-').forEach(function(v) { bx.push(isNaN(parseFloat(v)) ? v : parseFloat(v)) });

for (let i = 0; ax && bx && i < ax.length && i < bx.length; i++) { if (ax[i] !== bx[i]) { return ax[i] < bx[i] ? -1 : 1; } }

return ax.length - bx.length; };

使用方法如下:

const array = ['camelCase1', 'camelCase11', 'camelCase2'];

console.log(array.sort(orderByCamelCase)); // ['camelCase1', 'camelCase2', 'camelCase11']

相关内容

热门资讯

分享透视!hhpoker万能辅... 分享透视!hhpoker万能辅助器,微乐小程序辅助工具2025,课程教程(确实有挂)-哔哩哔哩该软件...
普及透视!hhpoker德州真... 普及透视!hhpoker德州真的假的,微乐广西小程序,课程教程(有挂技术)-哔哩哔哩1、游戏颠覆性的...
推荐透视!wepoker轻量版... 推荐透视!wepoker轻量版透视,微乐自建房道具有用吗,操作教程(有挂规律)-哔哩哔哩1、实时we...
揭幕透视!hhpoker有透视... 您好,hhpoker有透视功能吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
总结透视!werplan外卦神... 总结透视!werplan外卦神器,在哪里下载微乐自建房辅助软件,操作教程(真的有挂)-哔哩哔哩1、游...
科普透视!wepoker有透视... 科普透视!wepoker有透视功能吗,微信微乐小程序辅助器免费安装,方式教程(有挂解密)-哔哩哔哩1...
解谜透视!aapoker透视方... 解谜透视!aapoker透视方法,微信小程序微乐辅助器破解版,教材教程(竟然有挂)-哔哩哔哩1.aa...
揭幕透视!hhpoker免费辅... 揭幕透视!hhpoker免费辅助器,微乐山西威信小程序,绝活儿教程(有挂秘籍)-哔哩哔哩hhpoke...
揭露透视!wepoker有没有... 揭露透视!wepoker有没有挂,万能透视辅助器免费版,诀窍教程(有挂详细)-哔哩哔哩1、wepok...
解谜透视!wepoker可以开... 您好,wepoker可以开透视吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...