We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e020ce4 commit 3c326d8Copy full SHA for 3c326d8
algorithms/harmless_ransom_note
@@ -0,0 +1,34 @@
1
+// Check if the provided paragraph have enough words to make the provided sentence.
2
+
3
+function harmlessRansomNote(sentence, paragraph){
4
5
+ const sentenceArr = sentence.split(" ");
6
+ const paragraphArr = paragraph.split(" ");
7
+ let paragraphObj = {};
8
+ let isSentencePossible = true;
9
10
+ paragraphArr.forEach(function(word){
11
12
+ if (!paragraphObj[word]) paragraphObj[word] = 0;
13
+ paragraphObj[word]++;
14
15
+ });
16
17
18
+ sentenceArr.forEach(function(word){
19
20
+ if (paragraphObj[word]) {
21
22
+ paragraphObj[word]--;
23
+ if (paragraphObj[word] < 0) isSentencePossible = false;
24
+ }
25
26
+ else isSentencePossible = false;
27
28
29
30
+ return isSentencePossible;
31
32
+}
33
34
+harmlessRansomNote('i am here', 'i am here ok. come on.. i am here');
0 commit comments