Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(params) {
- let command = params.shift();
- let bestMovie = "";
- let points = 0;
- let bestPoints = 0;
- let counter = 0;
- while (command !== "STOP") {
- let movieTitle = command;
- counter++;
- points = 0;
- for (let i = 0; i < movieTitle.length; i++) {
- let letter = movieTitle[i];
- let symbol = letter.charCodeAt(0);
- points += symbol;
- if (letter === letter.toLowerCase()) {
- points -= movieTitle.length * 2;
- } else if (letter === letter.toUpperCase()) {
- points -= movieTitle.length;
- }
- }
- if (points > bestPoints) {
- bestPoints = points;
- bestMovie = movieTitle;
- }
- // Stopping the loop
- if (counter === 7) {
- console.log("The limit is reached.");
- console.log(
- `The best movie for you is ${bestMovie} with ${bestPoints} ASCII sum.`
- );
- break;
- }
- command = params.shift();
- }
- if (command === "STOP") {
- console.log(
- `The best movie for you is ${bestMovie} with ${bestPoints} ASCII sum.`
- );
- }
- }
Add Comment
Please, Sign In to add comment