Solve this question using laravel collection
Budget: $10 – $30 USD
<?php
/*
* Using collection pipeline programming, calculate ranks for the given teams based on their respective scores. Same scores should be ranked equally
* If multiple teams get the same rank, the next ranks should be skipped based on the team count.
* e.g. If Team B & C gets second rank, 3rd rank should skipped & the team eligible for the 3rd rank should be given 4th rank.
*
* Do not use any loops, if statements, or ternary operators.
*/
$scores = collect ([
['score' => 76, 'team' => 'A'],
['score' => 62, 'team' => 'B'],
['score' => 82, 'team' => 'C'],
['score' => 86, 'team' => 'D'],
['score' => 91, 'team' => 'E'],
['score' => 67, 'team' => 'F'],
['score' => 67, 'team' => 'G'],
['score' => 82, 'team' => 'H'],
]);
Answer should be
91 rank 1
86 rank2
82 rank 3
82 rank 3
76 rank 5
67 rank 6
67 rank 6
62 rank 8
/*
* Using collection pipeline programming, calculate ranks for the given teams based on their respective scores. Same scores should be ranked equally
* If multiple teams get the same rank, the next ranks should be skipped based on the team count.
* e.g. If Team B & C gets second rank, 3rd rank should skipped & the team eligible for the 3rd rank should be given 4th rank.
*
* Do not use any loops, if statements, or ternary operators.
*/
$scores = collect ([
['score' => 76, 'team' => 'A'],
['score' => 62, 'team' => 'B'],
['score' => 82, 'team' => 'C'],
['score' => 86, 'team' => 'D'],
['score' => 91, 'team' => 'E'],
['score' => 67, 'team' => 'F'],
['score' => 67, 'team' => 'G'],
['score' => 82, 'team' => 'H'],
]);
Answer should be
91 rank 1
86 rank2
82 rank 3
82 rank 3
76 rank 5
67 rank 6
67 rank 6
62 rank 8