-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharmlessRansom.js
More file actions
31 lines (27 loc) · 815 Bytes
/
harmlessRansom.js
File metadata and controls
31 lines (27 loc) · 815 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
27
28
29
30
31
function harmlessRansomNote (noteText, magazineText) {
const noteArr = noteText.split(' ');
const magazineArr = magazineText.split(' ');
const magazineObj = {};
magazineArr.forEach(word => {
if (!magazineObj[word]) {
magazineObj[word] = 0;
}
magazineObj[word]++;
});
let noteIsPossible = 'Yes';
noteArr.forEach(word => {
if (magazineObj[word]) {
magazineObj[word]--;
if (magazineObj[word] < 0) {
noteIsPossible = 'No';
}
} else {
noteIsPossible = 'No';
}
});
return noteIsPossible;
}
console.log(harmlessRansomNote(
'glory of notorious day',
'The opposite of notorious glorious day could be a very challenge support to our glory days'
));