Skip to content

Latest commit

Β 

History

History

challenge-09

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 

Challenge #9: 🚦 Switch the lights

The city is illuminating with Christmas lights πŸŽ„, and as every year, they need to be fixed!

The lights come in two colors: πŸ”΄ and 🟒. For the display to be appropriate, they must always alternate. That is, if the first light is red, the second must be green, the third red, the fourth green, and so on.

We have been asked to write a function adjustLights that, given an array of strings with the color of each light, returns the minimum number of lights that need to be changed for the colors to alternate.

adjustLights(['🟒', 'πŸ”΄', '🟒', '🟒', '🟒'])
// -> 1 (change the fourth light to πŸ”΄)

adjustLights(['πŸ”΄', 'πŸ”΄', '🟒', '🟒', 'πŸ”΄'])
// -> 2 (change the second light to 🟒 and the third to πŸ”΄)

adjustLights(['🟒', 'πŸ”΄', '🟒', 'πŸ”΄', '🟒'])
// -> 0 (they are already alternating)

adjustLights(['πŸ”΄', 'πŸ”΄', 'πŸ”΄'])
// -> 1 (change the second light to 🟒)