Advertisement
TZinovieva

Ascii Sumator JS Fundamentals

Mar 10th, 2023
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function asciiSumator(input) {
  2.     let firstChar = input.shift();
  3.     let secondChar = input.shift();
  4.     let str = input.shift();
  5.     let start = Math.min(firstChar.charCodeAt(0), secondChar.charCodeAt(0));
  6.     let end = Math.max(firstChar.charCodeAt(0), secondChar.charCodeAt(0));
  7.     let sum = 0;
  8.     for (let i = 0; i < str.length; i++) {
  9.       let charCode = str.charCodeAt(i);
  10.       if (charCode > start && charCode < end) {
  11.         sum += charCode;
  12.       }
  13.     }
  14.     console.log(sum);
  15.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement