MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / tandemBicycle

Function tandemBicycle

greedy/tandem-bicycle.js:3–14  ·  view source on GitHub ↗
(redShirtSpeeds, blueShirtSpeeds, fastest)

Source from the content-addressed store, hash-verified

1// time O(n log n) because we need to sorted the array
2// space O(1)
3function tandemBicycle(redShirtSpeeds, blueShirtSpeeds, fastest) {
4 let totalSpeed = 0;
5 redShirtSpeeds.sort((a, b) => b - a);
6 if (fastest) {
7 blueShirtSpeeds.sort((a, b) => a - b);
8 totalSpeed += getTotalSpeedHelper(redShirtSpeeds, blueShirtSpeeds);
9 } else {
10 blueShirtSpeeds.sort((a, b) => b - a);
11 totalSpeed += getTotalSpeedHelper(redShirtSpeeds, blueShirtSpeeds);
12 }
13 return totalSpeed;
14}
15
16function getTotalSpeedHelper(redShirtSpeeds, blueShirtSpeeds) {
17 let totalSpeed = 0;

Callers 1

tandem-bicycle.jsFile · 0.70

Calls 1

getTotalSpeedHelperFunction · 0.85

Tested by

no test coverage detected