//组合排列let array = [‘1‘,‘2‘,‘3‘] function getGroup(data, index = 0, group = []) { let need_apply = []; need_apply.push(data[index]); for (var i = 0; i < group.length; i++) { need_apply.push(group[i] + ‘ ‘ + data[index]); } group.push.apply(group, need_apply); if (index + 1 >= data.length) return group; else return getGroup(data, index + 1, group); }//排序 let list = getGroup(array).sort((a,b)=>{ if (a.length < b.length ) { return 1 } if (a.length > b.length ) { return -1 } return 0 })
原文地址:https://www.cnblogs.com/web-Development/p/12342062.html
时间: 2024-11-10 14:46:09