curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68b7687dded630607aceccaf.md
Given an array of numbers representing the speed at which vehicles were observed traveling, and a number representing the speed limit, return an array with two items, the number of vehicles that were speeding, followed by the average amount beyond the speed limit of those vehicles.
[0, 0].speeding([50, 60, 55], 60) should return [0, 0].
assert.deepEqual(speeding([50, 60, 55], 60), [0, 0]);
speeding([58, 50, 60, 55], 55) should return [2, 4].
assert.deepEqual(speeding([58, 50, 60, 55], 55), [2, 4]);
speeding([61, 81, 74, 88, 65, 71, 68], 70) should return [4, 8.5].
assert.deepEqual(speeding([61, 81, 74, 88, 65, 71, 68], 70), [4, 8.5]);
speeding([100, 105, 95, 102], 100) should return [2, 3.5].
assert.deepEqual(speeding([100, 105, 95, 102], 100), [2, 3.5]);
speeding([40, 45, 44, 50, 112, 39], 55) should return [1, 57].
assert.deepEqual(speeding([40, 45, 44, 50, 112, 39], 55), [1, 57]);
function speeding(speeds, limit) {
return speeds;
}
function speeding(speeds, limit) {
let speeding = 0;
let totalOver = 0;
for (let speed of speeds) {
if (speed > limit) {
speeding++;
totalOver += (speed - limit);
}
}
if (speeding === 0) return [0, 0];
return [speeding, totalOver / speeding];
}