Pages

Saturday, June 25, 2016

Coding challenge to be solved with Underscore functions....

Given a list of arrays, return the total length of all arrays added up.

For example, if the length of the first array was 5, and the second was 10, the total length of all arrays would be 15.

You can use the below arrays for testing:


var array1 = [[1],[2],[3],[4].[5]];
var array2 = ["a", "b"];
var array3 = [{name : "John"}, {age : 21}];
var array4 = [1,2,3,4,5,6,7,8,9,0];


19 should be returned.


Solution is in the comments.

1 comment:

  1. var lengthCounter = function(){
    return _.reduce(arguments, function(a, b){
    return a + b.length;
    },0)


    }

    ReplyDelete