Skip to content

Instantly share code, notes, and snippets.

@welefen
Last active December 25, 2015 06:29
Show Gist options
  • Save welefen/6932225 to your computer and use it in GitHub Desktop.
Save welefen/6932225 to your computer and use it in GitHub Desktop.
建立css选择器的压缩字典
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
}
@welefen
Copy link
Author

welefen commented Oct 11, 2013

var list = getDict(1); //建立一个字符的压缩字典,a-z
var dlist = getDict(2); //建立一个和二个字符的压缩字典

@welefen
Copy link
Author

welefen commented Oct 11, 2013

1个字符的压缩字典有26个
1和2个字符的压缩字典有702个,
如果加上$_-字符就更多了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment