Skip to content

Instantly share code, notes, and snippets.

@NaWer
Last active December 27, 2015 13:59
Show Gist options
  • Save NaWer/7337583 to your computer and use it in GitHub Desktop.
Save NaWer/7337583 to your computer and use it in GitHub Desktop.
Convert letters to digits using "old" phone keybord
var _in = 'erwan123';
var _out = [];
var map = ['0 ','1','2abc','3def','4ghi','5jkl','6mno','7pqrs','8tuv','9wxyz'];
for(var i = 0; i < _in.length; i++)
{
for (var j = 0; j < map.length; j++)
{
if (map[j] && map[j].indexOf(_in[i]) > -1)
{
_out.push(j);
break;
}
}
}
console.log(_out.join('')); // output 37926123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment