What does this code do?

K

keekeekee17

Someone is asking me what the following code does:

function foo(pr, s, vect)
{
var len = vect.length;
if (len == 1) {
return pr(vect[0], s);
} else {
return foo(pr, pr(vect[0], s), vect.slice(1,len));
}
}

I'm unfamiliar with vectors -- which I suppose is what vect is
supposed to be -- and don't know what slice() might be. Any ideas?

Gabe
 
B

Ben Pfaff

Someone is asking me what the following code does:

function foo(pr, s, vect)
{
var len = vect.length;

This isn't C: C doesn't have keywords "function" or "var".
 
G

Guest

Someone is asking me what the following code does:

function foo(pr, s, vect)
 {
     var len = vect.length;
     if (len == 1) {
         return pr(vect[0], s);
     } else {
         return foo(pr, pr(vect[0], s), vect.slice(1,len));
     }
 }

I'm unfamiliar with vectors -- which I suppose is what vect is
supposed to be -- and don't know what slice() might be.  Any ideas?

http://en.wikipedia.org/wiki/Euclidean_vector
 
C

Curtis Dyer

You might ask them what language they're using, because it doesn't
appear to be C.
function foo(pr, s, vect)
{
var len = vect.length;
if (len == 1) {
return pr(vect[0], s);
} else {
return foo(pr, pr(vect[0], s), vect.slice(1,len));
}
}

I'm unfamiliar with vectors -- which I suppose is what vect is
supposed to be -- and don't know what slice() might be. Any ideas?

Gabe

Might ask on a Pascal group, but I think you will need to read the documentation.

It also looks like it could be ECMAScript. If it is, try
comp.lang.javascript.
 
Joined
Mar 12, 2009
Messages
1
Reaction score
0
This might help.

The java script code Uses function "pr" to update the value of "s" by operating on the first element of a simple array "vect" till all the elements in "vect" are used up.

i.e Initially if 's' = 0; and if function 'pr' is written in such a way that it calculates : s + vect[0]
Then this code can be used to find sum of all elements in the original array vect.


Enjoy!



Someone is asking me what the following code does:

function foo(pr, s, vect)
{
var len = vect.length;
if (len == 1) {
return pr(vect[0], s);
} else {
return foo(pr, pr(vect[0], s), vect.slice(1,len));
}
}

I'm unfamiliar with vectors -- which I suppose is what vect is
supposed to be -- and don't know what slice() might be. Any ideas?

Gabe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top