.reduce() arguments / Projects: "Cash Register"

Tell us what’s happening:
Simple question about this code in the solution. I know methods often allow you to pass arguments by other names like X, el, item or when the prototype is expecting (accumulator, current value), (acc, cur), but acc.total seems to be initializing an object Key here. Am I getting that correctly? I have searched for .total as a JS property and haven’t found anything.

Your code so far

 // Transform CID array into drawer object
  var register = cid.reduce(
    function(acc, curr) {
      acc.total += curr[1];
      acc[curr[0]] = curr[1];
      return acc;
    { total: 0 }

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

this is the starting value of the accumulator, so the accumulator is an object with a property called total, acc.total access this property

1 Like

Whaaaat? The accumulator is an object? Mind blown. This helps me SO much!

1 Like

Whaaaat? The accumulator is an object? Mind blown.

in this case yes, the reduce method accepts a second argument that determine the starting value of the accumulator

maybe take a look at the documebtation on reduce on devdocs.io ?

I’m not familiar with that site. What I DID do yesterday was to play with console.log() and the acc object in a few of the solutions posted. That actually opens a lot of options for how I will finish the project. Been feeling more confident on the last five projects. Printing out sample solutions AFTER I solve it and writing notes on them. This is my final project for this cert. thanks for all the help.

it’s the documentation site created by freecodecamp
there are many around, find one you like and consult it as often as you need to research stuff