Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Commonmark migration
Source Link

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why

  • xx.functionABC(param2,param3)

    xx.functionABC(param2,param3)

    is the same as

is the same as

  • functionABC(param1,param2,param3)

    functionABC(param1,param2,param3)

Thanks for the reply everyone!


Thanks for all the comments and answers!

I feel stupid for not checking with other methods first (or shouldn't try with a built in function).

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why

  • xx.functionABC(param2,param3)

is the same as

  • functionABC(param1,param2,param3)

Thanks for the reply everyone!


Thanks for all the comments and answers!

I feel stupid for not checking with other methods first (or shouldn't try with a built in function).

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why

  • xx.functionABC(param2,param3)

    is the same as

  • functionABC(param1,param2,param3)

Thanks for the reply everyone!


Thanks for all the comments and answers!

I feel stupid for not checking with other methods first (or shouldn't try with a built in function).

added 164 characters in body
Source Link
Kiong
  • 851
  • 1
  • 9
  • 29

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why

  • xx.functionABC(param2,param3)

is the same as

  • functionABC(param1,param2,param3)

Thanks for the reply everyone!


Thanks for all the comments and answers!

I feel stupid for not checking with other methods first (or shouldn't try with a built in function).

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why

  • xx.functionABC(param2,param3)

is the same as

  • functionABC(param1,param2,param3)

Thanks for the reply everyone!

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why

  • xx.functionABC(param2,param3)

is the same as

  • functionABC(param1,param2,param3)

Thanks for the reply everyone!


Thanks for all the comments and answers!

I feel stupid for not checking with other methods first (or shouldn't try with a built in function).

added 17 characters in body
Source Link
Kiong
  • 851
  • 1
  • 9
  • 29

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why xx.functionABC(param2,param3)

  • xx.functionABC(param2,param3)

is the same as functionABC(param1,param2,param3).

  • functionABC(param1,param2,param3)

Thanks for the reply everyone!

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why xx.functionABC(param2,param3) is the same as functionABC(param1,param2,param3).

Thanks for the reply everyone!

Firstly, sorry for the not specific title. I don't know how to call this.

Ok, here goes my question.

I am going to take Javascript's reduce function here.

I know the "reduce" function is defined as follows

function reduce(array, combine, start) {
 var current = start;
 for (var i = 0; i < array.length; i++)
 current = combine(current, array[i]);
 return current;
}

Well, what I don't understand is this.

Why

[1, 2, 3, 4].reduce(function(a, b) {
 return a + b;
}, 0);

and

reduce([1, 2, 3, 4], function(a, b) {
 return a + b;
}, 0);

returns the same result of "10"?

I know how the function works. I just don't understand why

  • xx.functionABC(param2,param3)

is the same as

  • functionABC(param1,param2,param3)

Thanks for the reply everyone!

Source Link
Kiong
  • 851
  • 1
  • 9
  • 29
Loading
lang-js

AltStyle によって変換されたページ (->オリジナル) /