PortalPlayer

amountOfCertainCharacter

Aug 30th, 2020 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype.amountOfCertainCharacter = function(char) {
  2.     return this.split("").filter(k => k === char).length
  3. }
  4.  
  5. // example
  6. // code | expected output
  7.  
  8. "testing".amountOfCertainCharacter("t") // 2
  9. "testing".amountOfCertainCharacter("e") // 1
  10.  
  11. "testing".amountOfCertainCharacter()    // 0
  12. "testing".amountOfCertainCharacter("q") // 0
Add Comment
Please, Sign In to add comment