-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathharmlessRansomNote.js
25 lines (21 loc) · 1008 Bytes
/
harmlessRansomNote.js
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
function harmlessRansomNote(noteText, magazineText) {
let noteArr = noteText.split(" ");
let magazineArr = magazineText.split(" ");
let magazineObj = {};
magazineArr.forEach(word => {
if (!magazineObj[word]) magazineObj[word] = 0;
magazineObj[word]++;
});
let noteIsPossible = true;
noteArr.forEach(word => {
if (magazineObj[word]) {
magazineObj[word]--;
if (magazineObj[word] < 0) noteIsPossible = false;
} else noteIsPossible = false;
});
return noteIsPossible;
}
harmlessRansomNote(
"this is a secret note for you from a secret admirer",
"puerto rico is a place of great wonder and excitement it has many secret waterfall locations that i am an admirer of you must hike quite a distance to find the secret places as they are far from populated areas but it is worth the effort a tip i have for you is to go early in the morning when it is not so hot out also note that you must wear hiking boots this is one of the best places i have ever visited"
);