Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve ([str]) {
- let words = {}
- for (let i = 0; i < str.length; i++) {
- let word = []
- let code = str[i].charCodeAt(0)
- while (
- i < str.length &&
- ((code >= 65 && code <= 90) ||
- (code >= 97 && code <= 122) ||
- (code >= 48 && code <= 57) ||
- code === 95)
- ) {
- word.push(String.fromCharCode(code))
- i++
- if (i < str.length) {
- code = str[i].charCodeAt(0)
- }
- }
- word = word.join('')
- if (word.length > 0) {
- if (!words.hasOwnProperty(word)) {
- words[word] = 0
- }
- words[word]++
- }
- }
- console.log(JSON.stringify(words))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement