Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function favoriteMovie(input) {
- let bestMovie = "";
- let bestAsciiSum = 0;
- let counter = 0;
- let movie;
- while ((movie = input.shift()) !== "STOP" && ++counter !== 7) {
- let asciiSum = 0;
- for (let j = 0; j < movie.length; j++) {
- asciiSum += movie[j].charCodeAt(0);
- if (movie[j].charCodeAt(0) > 96 && movie[j].charCodeAt(0) < 123) {
- asciiSum -= movie.length * 2;
- } else if (movie[j].charCodeAt(0) > 64 && movie[j].charCodeAt(0) < 91) {
- asciiSum -= movie.length;
- }
- if (asciiSum > bestAsciiSum) {
- bestAsciiSum = asciiSum;
- bestMovie = movie;
- }
- }
- }
- if (counter === 7) {
- console.log("The limit is reached.");
- }
- console.log(`The best movie for you is ${bestMovie} with ${bestAsciiSum} ASCII sum.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement