Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Code Challenge Resurrected!

In the fewest bytes of JavaScript code, how would you write a function that accepts a phone number and returns an array of phone words?

function phoneWord(pn){/* your code here */}

phoneWord(2255288) should return an array with 2187 (3*3*3*3*3*3*3) different items, one of which should be 'CALLATT'.

Let's call this contest by 12/7/2004.

Good Luck!

• I really think it's better if this is a new thread instead of a years old one. Splitting.

• whats a phone word?

• Took me a minute too, but still not sure. Do you mean the words that could be made, based on the letters assigned to the numbers of the phone number?

Basscyst

• I would think a serverside method would be more effective due to the possible combinations.
here is one that runs a serverside although closed source - http://www.phonespell.org/
although it only find mnemonics.

• Code:
```Array.prototype.map = function(func) {
if (this.length) return [func(this[0])].concat(this.slice(1).map(func));
return [];
}
function phoneWord(pn) {
return (function(func, running, arr) {
if (arr.length)
return arguments.callee(func, func(arr[0], running), arr.slice(1));
return running;
})(function(a1, a2) {
if (a1.length)
return a2.map(function(el) { return el+a1[0] }).concat(arguments.callee(a1.slice(1), a2));
return [];
}, [""], pn.toString().split("").map(parseInt).map(
function(button) {
if (button)
return [3*button+59, 3*button+60, 3*button+61].map(String.fromCharCode);
return ["Y","Z"];
}));
}```
The map could be phased out but actually defining it instead of using anonymous lambda functions shortens the code, as the script relies on map in several areas. Also, the code could be compressed a good deal.

• ## Excellent!

Originally Posted by jkd
Code:
```Array.prototype.map = function(func) {
if (this.length) return [func(this[0])].concat(this.slice(1).map(func));
return [];
}
function phoneWord(pn) {
return (function(func, running, arr) {
if (arr.length)
return arguments.callee(func, func(arr[0], running), arr.slice(1));
return running;
})(function(a1, a2) {
if (a1.length)
return a2.map(function(el) { return el+a1[0] }).concat(arguments.callee(a1.slice(1), a2));
return [];
}, [""], pn.toString().split("").map(parseInt).map(
function(button) {
if (button)
return [3*button+59, 3*button+60, 3*button+61].map(String.fromCharCode);
return ["Y","Z"];
}));
}```
The map could be phased out but actually defining it instead of using anonymous lambda functions shortens the code, as the script relies on map in several areas. Also, the code could be compressed a good deal.
Excellent!

• The function
Code:
```<script>
function phoneWord( num, str, result)
{
var s  = ["0", "1", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"][num.charAt(0)];
str    = str == undefined ? "" : str;
result = result == undefined ? new Array() : result;
for(var i=0 ; i<s.length ; i++)
if(num.length > 1)
phoneWord(num.slice(1) , str + s.charAt(i), result)
else
result[result.length] = str + s.charAt(i);
return result;
}
</script>```
The test
Code:
```<script>
var x=phoneWord("2255288");
var y=phoneWord("769");

document.write("<textarea rows=40 cols=100>" + x + "</textarea>");
document.write("<textarea rows=3 cols=100>" + y + "</textarea>");
document.write("<textarea rows=3 cols=100>" + y[34] + "," + x[1674] + "</textarea>");
</script>```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•