Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 1, 2020 06:01 pm GMT

Daily Challenge 295 - Sort Leaderboards

In this challenge, you'll be given a leaderboard in the form of an array, as well as a list of strings. Using the information in the list, sort the leaderboard.

Example

array:

['John', 'Brian', 'Jim', 'Dave', 'Fred']

list:
['Dave +1', 'Fred +4', 'Brian -1']

The steps for our example would be:

# Dave up 1['John', 'Brian', 'Dave', 'Jim', 'Fred']# Fred up 4['Fred', 'John', 'Brian', 'Dave', 'Jim']# Brian down 1['Fred', 'John', 'Dave', 'Brian', 'Jim']

Then, we return the completed leaderboard:

['Fred', 'John', 'Dave', 'Brian', 'Jim']

Strings will never ask you to move a name higher or lower than possible. The strings in the list will always be a name in the leaderboard, followed by a space and a positive or negative number.

Tests

leaderboardSort(['John', 'Brian', 'Jim', 'Dave', 'Fred'], ['Dave +1', 'Fred +4', 'Brian -1'])
leaderboardSort(['Bob', 'Larry', 'Kevin', 'Jack', 'Max'], ['Max +3', 'Kevin -1', 'Kevin +3'])

Good luck!

This challenge comes from topping on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email [email protected] with your suggestions!


Original Link: https://dev.to/thepracticaldev/daily-challenge-295-sort-leaderboards-4a85

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To