0
Function findMax(objects) {
    var values = [];

    // We parse each object in array
    _.each(objects, parseObject());

    function parseObject(object) {
        // We add a value from an object to values array
        values.push(object.value);
    }

    // We pick the maximum value
    return Math.Max(values);
}

How to fix errors in code ?

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
Elrico
  • 1
  • 2
  • This was quite easy to spot, but in future you should put the actual error in your question too. – CodingIntrigue Mar 20 '15 at 15:48
  • possible duplicate of [How can I debug my JavaScript code?](http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code) – Liam Mar 20 '15 at 15:49

2 Answers2

1

Function is not the identifier you're looking for. It's function.

Also, you are executing parseObject immediately. I assume you wanted to pass it in as a callback to _.each:

function findMax(objects) {
    var values = [];

    // We parse each object in array
    _.each(objects, parseObject);

    function parseObject(object) {
        // We add a value from an object to values array
        values.push(object.value);
    }

    // We pick the maximum value
    return Math.Max(values);
}
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
1

_.each function accepts a function reference as a second parameter, instead of it you invoked the function.

Replace _.each(objects, parseObject()); with _.each(objects, parseObject);

tuks
  • 800
  • 3
  • 11
  • 27