# Tandem Bicycle

<figure><img src="https://3743232000-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHW2IQuh2PFpWJDvBz2FF%2Fuploads%2Fgit-blob-103bb1370ba3eeaa2c855b8c8e61d8cd79871479%2FScreenshot%202023-01-20%20at%2019.02.35.png?alt=media" alt=""><figcaption></figcaption></figure>

```javascript
function tandemBicycle(redShirtSpeeds, blueShirtSpeeds, fastest) {
  redShirtSpeeds.sort((a, b) => a - b);
  blueShirtSpeeds.sort((a, b) => a - b);

  if (fastest === true) {
    blueShirtSpeeds.sort((a, b) => b - a);
  }

  let totalSpeed = 0;
  for (let i = 0; i < redShirtSpeeds.length; i++) {
    const max = Math.max(redShirtSpeeds[i], blueShirtSpeeds[i]);
    totalSpeed += max;
  }
  
  return totalSpeed;
}

// Do not edit the line below.
exports.tandemBicycle = tandemBicycle;
```
