Skip to content

Instantly share code, notes, and snippets.

@huttj
Last active August 29, 2015 14:12
Show Gist options
  • Save huttj/9ba4f27d7eecd7bcc467 to your computer and use it in GitHub Desktop.
Save huttj/9ba4f27d7eecd7bcc467 to your computer and use it in GitHub Desktop.
Chinese version of lookSaySequence--for kicks.
var lookSaySequence = (function() {
var words = {
'0': '零',
'1': '一',
'2': '二',
'3': '三',
'4': '四',
'5': '五',
'6': '六',
'7': '七',
'8': '八',
'9': '九'
};
var re = new RegExp('0123456789'.split('').join('+|') + '+', 'g');
return function(num) {
num = ''+num;
var arry = num.match(re);
var result = arry.map(function(n) {
return words[n.length] + '个' + words[n.charAt(0)];
});
if (result.length === 1) return result[0];
if (result.length === 2) return result[0] + '和' + result[1];
return result.slice(0, result.length - 1).join('、') + '、和 ' + result.slice(-1);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment