Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //s - sergeant; c - corporal; p - private
- const n = +gets();
- const soldiers = gets().split(' ');
- const sortedSoldiers = (soldiers) => {
- const rankOrder = { S: 0, C: 1, P: 2 };
- soldiers.sort((a, b) => {
- const rankA = a.charAt(0);
- const rankB = b.charAt(0);
- if(rankOrder[rankA] < rankOrder[rankB]){
- return -1;
- }else if(rankOrder[rankA] > rankOrder[rankB]){
- return 1;
- }else{
- return 0;
- }
- });
- return soldiers;
- };
- console.log(sortedSoldiers(soldiers).join(' '))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement