const countOccurrences = (text, str) => { let {length} = text.split(str); return --length; }; console.log(countOccurrences('abefhiefj', 'ef'));