Advertisement
Shell_Casing

Untitled

Jan 9th, 2019
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // checking for the same number of Os (letter as in Oh) and Xs in a string;
  2.  
  3. function sameXOAmount1(str) {
  4.  
  5.     let numOfOs = 0;
  6.     let numOfXs = 0;
  7.  
  8.     let arr = Array.from(str);
  9.     arr.forEach(letter => {
  10.         if (letter.toLowerCase() == 'o') {
  11.             numOfOs++;
  12.         }
  13.         if (letter.toLowerCase() == 'x') {
  14.             numOfXs++;
  15.         }
  16.     });
  17.  
  18.     return numOfOs == numOfXs;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement