Q
What is the result of _.reduce([1, 2, 3], function(sum, num) { return sum + num; }, 0)?

Answer & Solution

Answer: Option A
Solution:
The _.reduce function reduces a list of values to a single value by iteratively combining each value with an accumulator.
Related Questions on Average

What does the _.each function do in Underscore.js?

A). Iterates over a list of elements

B). Creates a new array with transformed values

C). Filters values in a list

D). Reduces the list to a single value

How do you extend an object with properties from other objects in Underscore.js?

A). _.clone

B). _.extend

C). _.omit

D). _.pick

What is the output of _.last([1, 2, 3, 4, 5], 2)?

A). [1, 2]

B). [4, 5]

C). [5]

D). [3, 4, 5]

What does _.keys({one: 1, two: 2, three: 3}) return?

A). [1, 2, 3]

B). ['one', 'two', 'three']

C). ['1', '2', '3']

D). [1, 2, 'three']

Which function is used to clone an object in Underscore.js?

A). _.extend

B). _.clone

C). _.map

D). _.filter

What is the result of _.map([1, 2, 3], function(num) { return num * 3; })?

A). [1, 2, 3]

B). [3, 6, 9]

C). [2, 4, 6]

D). [3, 6, 9, 12]

How do you shuffle the elements of an array in Underscore.js?

A). _.each

B). _.shuffle

C). _.sample

D). _.random

Which function is used to find unique elements in an array in Underscore.js?

A). _.first

B). _.last

C). _.uniq

D). _.filter

What does the _.filter function do in Underscore.js?

A). Iterates over a list of elements

B). Creates a new array with transformed values

C). Filters values in a list

D). Reduces the list to a single value

How do you flatten a nested array using Underscore.js?

A). _.map

B). _.flatten

C). _.filter

D). _.reduce