Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oscars(input) {
- let name = input[0];
- let points = Number(input[1]);
- let juryNum = Number(input[2]);
- for (let i = 3; i < juryNum * 2 + 3; i++) {
- let juryName = input[i++];
- let currentPoint = Number(input[i]);
- points += juryName.length * currentPoint / 2;
- if (points > 1250.5) {
- break;
- }
- }
- if (points > 1250.5) {
- console.log(`Congratulations, ${name} got a nominee for leading role with ${points.toFixed(1)}!`);
- } else {
- console.log(`Sorry, ${name} you need ${(1250.5 - points).toFixed(1)} more!`);
- }
- }
- Решение със shift():
- function oscars(input) {
- let name = input.shift();
- let points = Number(input.shift());
- let juryNum = Number(input.shift());
- for (let i = 0; i < juryNum; i++) {
- let juryName = input.shift();
- let currentPoint = Number(input.shift());
- points += juryName.length * currentPoint / 2;
- if (points > 1250.5) {
- break;
- }
- }
- if (points > 1250.5) {
- console.log(`Congratulations, ${name} got a nominee for leading role with ${points.toFixed(1)}!`);
- } else {
- console.log(`Sorry, ${name} you need ${(1250.5 - points).toFixed(1)} more!`);
- }
- }
- Решение с while и shift():
- function oscars(input) {
- let name = input.shift();
- let points = Number(input.shift());
- let juryNum = Number(input.shift());
- while (juryNum-- !== 0 && points < 1250.5) {
- let juryName = input.shift();
- let currentPoint = Number(input.shift());
- points += juryName.length * currentPoint / 2;
- }
- if (points > 1250.5) {
- console.log(`Congratulations, ${name} got a nominee for leading role with ${points.toFixed(1)}!`);
- } else {
- console.log(`Sorry, ${name} you need ${(1250.5 - points).toFixed(1)} more!`);
- }
- }
Add Comment
Please, Sign In to add comment