Quick actions

cmd+k|ctrl+k

Navigation

Languages

Challenge: Longest run

Snippet info

Language

JavaScript

Visibility

public

Author

noemi-techfems

Created

2024-09-06T18:52:08.431713Z

Updated

2024-09-06T18:52:08.431713Z

// Here's the explanation of the challenge -- when you're done reading it,
// click on `main.js` above to get started with the challenge!

// Have you ever sat by the road and counted the cars as they pass by?
// Sometimes coincidences happen and you see three yellow cars in a row.
// Let's use code to keep track of the cars!

// ## Description

// In this challenge, you will write a `longestRun` function that receives a
// list (array) as an argument. Each element in the list is a string
// containing a color. The list represents the colors of the different cars
// you see running down the road.

// For example, if you see a red car, then two blue cars and then a yellow
// car, your function would be invoked like:

// longestRun(["red", "blue", "blue", "yellow"])

// Your function should return the name of the color that has the longest run.
// That is, the color that appears the most times in a row, next to itself,
// without other colors in between.

// For example, if you see two blue cars, then four red cars,
// and then three blue cars, the red cars are the ones that had the longest
// run, as there was a run of four red cars. Even if there were more blue
// cars _in total_, the longest **uninterrupted** run was that of the red cars.

// You can assume that the list will not be empty, and that a single color
// appears the most times in a row.
INFO