Arrow Function - clarifications (21 Days of coding challenge)

Hi coders,
I’m looking different solutions that there were for the challenge "21 Days of Coding Challenge " from LighthouseLabs and I came across this arrow function:

const doorToDoor = (volunteers = [], neighbourhoods =["one"]) => {
  return Math.floor(neighbourhoods.length / volunteers.length);

I have some doubts about the second “argument” of function , neighbourhoods = ["one"],
I don’t understand why “one” was used and the array passed in the function was not declared without values or other values.
I put the link to where I found this solution :

Short answer; read the last point of the github page (can’t divide by zero) :wink: … BUT i agree with you…

if you were to call doorToDoor() with no arguments, then the function will default to:

volunteers = [],
neighbourhoods =["one"]

the ‘one’ is just a placeholder to make sure neighbourhoods has at least 1 for a length…

and the code is:

const doorToDoor = (volunteers = [], neighbourhoods =["one"]) => {
  return Math.floor(neighbourhoods.length / volunteers.length);

so default is 1/0 :thinking:

this is a case in which default parameters where used

you can read about what default parameters are and how they work, here:

1 Like

Both problem and solution especially are terrible :slight_smile:
What if you have 5 neighborhoods and 6 students, answer would be 0?

Uhm, i think is a quite obvious typo, you can signal it (the non-empty array should be the volunteer’s one)^^

Mh, i guess the reasoning behind the formula used is that none of the volunteers has to go through an entire neighborhood (1), each volunteer would be assigned to 0.83 part of it :stuck_out_tongue:
But, to answer the question probably would be much appropriate to use Math.ceil, because you will visit at least one neighborhood (it doesn’t matter if you go through all the houses) and in case you would be assigned to a 1.01 neighborhood you would still have to visit 2^^

If you have 5 neighborhoods and 6 volunteers answer should be 0.83 as that’s how much neighborhoods they will visit in average. I don’t quite get, why would you use Math.floor() or Math.ceil() for that :slight_smile:

And the problem might be a little less ambiguous if it either specifies ‘in average’ or asks for the output in a form of entries with number of jobs next to volunteer

Thanks @pjonp , In fact I want to know what “one” was ,becuase I nver seen before. Sometimes I use empty value into array.

I will check, thanks for resource @ilenia

I resolved this challenge only doing the division on length’s arrays.