Guest User

Untitled

a guest
Feb 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. function harmlessRansomNote(noteText, magazineText) {
  2. var noteArr = noteText.split(' ');
  3. var magazineArr = magazineText.split(' ');
  4. var magazineObj = {};
  5.  
  6. magazineArr.forEach(word => {
  7. if (!magazineObj[word]) magazineObj[word] = 0;
  8. magazineObj[word]++;
  9. });
  10.  
  11. var noteIsPossible = true;
  12. noteArr.forEach(word => {
  13. if (magazineObj[word]) {
  14. magazineObj[word]--;
  15. if (magazineObj[word] < 0) noteIsPossible = false;
  16. }
  17. else noteIsPossible = false;
  18. });
  19.  
  20. return noteIsPossible;
  21. }
  22. 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 locatoins 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');
Add Comment
Please, Sign In to add comment