Last active
December 25, 2015 06:29
-
-
Save welefen/6932225 to your computer and use it in GitHub Desktop.
建立css选择器的压缩字典
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 getDict(length, prefix){ | |
length = length || 1; | |
prefix = prefix || ""; | |
var chars = "abcdefghijklmnopqrstuvwxyz".split(""); | |
var result = []; | |
chars.forEach(function(char){ | |
result.push(prefix + char); | |
if(length>1){ | |
result.push.apply(result, getDict(length - 1, char)); | |
} | |
}) | |
result.sort(function(a, b){ | |
if(a.length == b.length){ | |
return a > b ? 1 : -1; | |
} | |
return a.length > b.length ? 1 : -1; | |
}) | |
return result | |
} |
1个字符的压缩字典有26个
1和2个字符的压缩字典有702个,
如果加上$_-字符就更多了
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var list = getDict(1); //建立一个字符的压缩字典,a-z
var dlist = getDict(2); //建立一个和二个字符的压缩字典