Last active
October 7, 2015 08:37
-
-
Save abidibo/579629db2244ff1eb3b3 to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var numberStringToText; | |
(function() { | |
var dict = { | |
'0': ' ', | |
'00': '0', | |
'1': '1', | |
'11': ',', | |
'111': '.', | |
'1111': ':', | |
'11111': '?', | |
'111111': '!', | |
'2': 'a', | |
'22': 'b', | |
'222': 'c', | |
'2222': '2', | |
'3': 'd', | |
'33': 'e', | |
'333': 'f', | |
'3333': '3', | |
'4': 'g', | |
'44': 'h', | |
'444': 'i', | |
'4444': '4', | |
'5': 'j', | |
'55': 'k', | |
'555': 'l', | |
'5555': '5', | |
'6': 'm', | |
'66': 'n', | |
'666': 'o', | |
'6666': '6', | |
'7': 'p', | |
'77': 'q', | |
'777': 'r', | |
'7777': 's', | |
'77777': '7', | |
'8': 't', | |
'88': 'u', | |
'888': 'v', | |
'8888': '8', | |
'9': 'w', | |
'99': 'x', | |
'999': 'y', | |
'9999': 'z', | |
'99999': '9' | |
}; | |
numberStringToText = function(number) { | |
var prev, | |
text = ''; | |
for(var i = 0, l = number.length; i < l; i++) { | |
if(!prev) { | |
prev = number[i]; | |
} | |
else if(number[i] == prev[0]) { | |
prev += number[i]; | |
if(i == l-1) { | |
text += dict[prev]; | |
} | |
} | |
else { | |
text += dict[prev]; | |
prev = number[i]!== '#' ? number[i] : ''; | |
} | |
} | |
return text; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment