Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- words_count = (sentences, word) => {
- let wordCount = 0
- // Hapus semua karakter kecuali alphabet, numeric, space dan ubah menjadi bentuk Array.
- sentencesArr = sentences.replace(/[^\w\s]/gi, '').split(' ')
- for (let i = 0; i < sentencesArr.length; i++) {
- if(sentencesArr[i].toLowerCase() == word.toLowerCase()) wordCount++
- }
- return wordCount
- }
- let setences = "`A wonderful serenity has taken possession of my entire soul, like these sweet
- mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in
- this spot, which was created for the bliss of souls like mine. I am so happy `
- console.log(words_count(setences, "like")) // 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement