Guest User

Untitled

a guest
May 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // Adding a String
  2.  
  3. // What I wish works:
  4. // 'hello ' + ' hello ' = 'hello hello '
  5.  
  6. // JS uses '+' operator for string concatenation
  7. console.log('hello ' + 'hello ')
  8.  
  9. // Subtracting a string
  10.  
  11. // What I wish worked:
  12. // 'hello hello' - 'hel' = 'lo lo '
  13.  
  14. // JS uses replace() for sring substitution
  15. console.log('hello hello '.replace(/hel/g, ''))
  16.  
  17. // Multiplying a string
  18.  
  19. // What I wish worked:
  20. // 'hello ' * 3 = 'hello hello hello '
  21.  
  22. // JS uses repeat() for string repitition
  23. console.log('hello '.repeat(3))
  24.  
  25. // Dividing a string
  26.  
  27. // What I wish worked:
  28. // 'hello hello hello ' / 'hello ' = ['hello ', 'hello ', 'hello ']
  29.  
  30. // JS uses split() for string splitting
  31. console.log('hello hello hello '.split(/(hello )/).filter(el => el))
Add Comment
Please, Sign In to add comment