1. 程式人生 > >輸入數字,逆轉並輸出漢字形式

輸入數字,逆轉並輸出漢字形式

function reverse(){
	var num = arguments[0];
	num = num.toString();
	var arr = num.split("");
	var newArr = arr.reverse();
	var word = ['零','壹','貳','叄','肆','伍','陸','柒','捌','玖'];
	var newArr2 = [];
	for(var i = 0; i < newArr.length; i++){
		for(var j =0; j < word.length; j++){
			if( arr[i] == j ){
				newArr2.push(word[j]);
			}
		}
	}
	newArr2 = newArr2.join("");
	document.write(newArr2);
}
reverse(2945);
//伍肆玖貳