TZinovieva

Characters In Range JS

Feb 1st, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function charactersinRange(char1, char2) {
  2.     let start = char1.charCodeAt(0);
  3.     let end = char2.charCodeAt(0);
  4.     let result = "";
  5.     if (start <= end) {
  6.         for (let i = start + 1; i < end; i++) {
  7.             result += String.fromCharCode(i) + " ";
  8.         }
  9.     } else {
  10.         for (let i = start - 1; i > end; i--) {
  11.             result = String.fromCharCode(i) + " " + result;
  12.         }
  13.     }
  14.     console.log(result.trim());
  15. }
Advertisement
Add Comment
Please, Sign In to add comment