Created
February 24, 2019 23:56
-
-
Save okovalov/a358c782a31c46e5d0cfcabcfb137cc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const harmlessRansomNote = (search, text) => { | |
let result = true | |
const textArr = text.toLowerCase().split(' ') | |
const searchArr = search.toLowerCase().split(' ') | |
const hash = {} | |
for (let idx in textArr) { | |
const word = textArr[idx] | |
if (!hash[word]) hash[word] = 0 | |
hash[word]++ | |
} | |
for (let idx in searchArr) { | |
const word = searchArr[idx] | |
if (!hash[word] || hash[word] < 1) { | |
result = false | |
break | |
} | |
hash[word]-- | |
} | |
return result | |
} | |
const search = 'this is so so so' | |
const text = 'is that this really abc is so so cool vvv' | |
const result = harmlessRansomNote(search, text) | |
console.log(`'${search}' is ${!result ? ' not' : '' } fully presented in '${text}', the result is '${result}'`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment