mirror of
https://github.com/seigler/natospell
synced 2025-07-27 00:56:10 +00:00
remove unused variable, pass through numerals (#2)
This commit is contained in:
parent
ea1b020651
commit
36f9aa873d
1 changed files with 8 additions and 1 deletions
9
main.js
9
main.js
|
@ -3,18 +3,25 @@
|
|||
var words, inputElement, outputElement;
|
||||
|
||||
function translate(input) {
|
||||
var i, length, output, key, a = 'a'.charCodeAt(0), z = 'z'.charCodeAt(0);
|
||||
var i, length, output, key, numKey, a = 'a'.charCodeAt(0), zero = '0'.charCodeAt(0);
|
||||
input = input.toLowerCase();
|
||||
output = "";
|
||||
length = input.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
key = input.charCodeAt(i) - a;
|
||||
numKey = input.charCodeAt(i) - zero;
|
||||
if (key >= 0 && key <= 26) {
|
||||
if (i > 0) {
|
||||
output += " ";
|
||||
}
|
||||
output += words[key];
|
||||
}
|
||||
else if(numKey >= 0 && numKey <= 10){
|
||||
if (i > 0) {
|
||||
output += " ";
|
||||
}
|
||||
output += numKey.toString();
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue