Last active
August 29, 2015 14:12
-
-
Save huttj/9ba4f27d7eecd7bcc467 to your computer and use it in GitHub Desktop.
Chinese version of lookSaySequence--for kicks.
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
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