Created
December 3, 2015 09:05
-
-
Save crimx/5ac48e7cfa81cd054015 to your computer and use it in GitHub Desktop.
计算字符串中出现最多的字符和次数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function count(s) { | |
var r = s.split('') | |
.sort() | |
.join('') | |
.match(/(\w)\1*/g) | |
.sort(function(a,b) { | |
return a.length < b.length | |
}); | |
return { | |
letter: r[0], | |
count: r.length | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment