标签:style blog http java color for
群里的提问,简单直接的流程式实现:
var arr1=[1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,6,7,7,‘1‘,‘1‘]; var res = []; var btn; for(var i =0;i<arr1.length;i++){ btn = false; for(var j = 0;j<res.length;j++){ if(arr1[i] === res[j].val){ res[j].count += 1; btn = true; break; } } if(!btn){ res.push({val:arr1[i],count:1}); } } for(var i =0;i<res.length;i++){ console.log(res[i]); }
标签:style blog http java color for
原文地址:http://www.cnblogs.com/tabooc/p/3698853.html