Re:Hiring technical talent: An exercise in clarity, patience...
by kyberias on Saturday May 14, 2022 @05:01AM
(#31376206)
Seems like you want to get the count of "leaves" in a tree expressed as array of arrays.
```
const lengthParam = (a) => {
let count = 0;
for(let c of a) {
if(Array.isArray(c)) {
count += lengthParam(c)
}
else {
count++;
}
}
return count;
};
```
Am I hired?
Like I could have a recursive solution that returns the sum of the length of the sub-arrays or I could just pass a mutable object and update the length there.
Which way would depend on the exact problem (i.e. Strings would be best collected in a StringBuilder rather than concatenated but `lengthParam` would probably more clear if it returned a number instead of using the Array).