Read here. Code on desktop. The coding workspace opens on screens 1024px and wider.
JavaScript interview question
Mean By
easy10 min
Compute the arithmetic mean of numeric scores derived from array items using a callback or a direct property key.
Requirements
Implement meanBy(array, iteratee). The criterion is either a callback (value, index, originalArray) => number or a direct property key such as score.
Evaluate each item exactly once, add its score, and divide by the number of items. Return NaN for empty input without invoking the callback.
Assume a dense array and a valid criterion returning finite numeric scores. Property keys refer to one property, not nested paths. Ordinary JavaScript floating-point arithmetic is sufficient.
Do not mutate or sort the input. Pass original indices and the original array to callbacks and propagate callback errors.