Advertisement
totobac

Untitled

Feb 5th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = ["5","1","go","1","there","5"];
  2.  
  3. let print = this.print || console.log;
  4. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  5.  
  6. let n = +gets();
  7. let sum = 0;
  8. let wordsResult = "";
  9.  
  10. for(let i = 0; i <= n ; i++)
  11. {
  12.    let str = gets();                       /////////////
  13.    let lastChar = str[str.length - 1]     ///////////////  TypeError: Cannot read property 'length' of undefined
  14.     if(lastChar >= "0" && lastChar <= "9") /////////////// При абсолютно същия код, но не в цикъл се държи нормално.
  15.     sum += str;
  16.     else
  17.     wordsResult = wordsResult + str + "-";
  18. }
  19. print(wordsResult);
  20. print(sum);
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement