PortalPlayer

removeUnnecessarySpaces

Jun 5th, 2021
744
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype.removeUnnecessarySpaces = function() {
  2.     return this.split(/ +/).join(" ").trim()
  3. }
  4.  
  5. // example
  6. // code | expected output
  7.  
  8. "  t  e  s  t  i  n  g  ".removeUnnecessarySpaces() // "t e s t i n g"
  9.  
  10. "".removeUnnecessarySpaces()                        // ""
  11. "testing".removeUnnecessarySpaces()                 // "testing"
RAW Paste Data