-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathransomNote.js
More file actions
26 lines (19 loc) · 936 Bytes
/
ransomNote.js
File metadata and controls
26 lines (19 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Requirement: from the text nodes check that ransome note is found or not
function ransomNote (textNote, magzineText) {
var textArray = textNote.toLowerCase().split(" ");
var magzineArray = magzineText.toLowerCase().split(" ");
var magzineObj = {};
var isSecret = true
magzineArray.forEach(word => {
if(!magzineObj[word]) magzineObj[word] = 0;
magzineObj[word]++;
});
textArray.forEach(word => {
if(magzineObj[word]){
magzineObj[word]--;
if(magzineObj[word] < 0 ) isSecret = false;
} else isSecret = false;
})
console.log(isSecret ? "Ransome Secret Found" : "Nothing found in the magzine");
}
ransomNote("Some text", "this is some text some this is some text some this is some text some this is some text some this is some text some this is some text some this is some text some this is some text some this is some text some");