We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Since it's not the most readable (wanted to keep it a reasonable one-liner), I'll explain it briefly:
The code loops through the contents of note element by element. If the element (word) is found in magazine it is removed from there and allowed through the filter function.
The code then checks whether the same number of elements as the size of note was returned after filtering to verify whether or not to return 'Yes' or 'No'.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
My JavaScript one-liner (ish) solution:
Since it's not the most readable (wanted to keep it a reasonable one-liner), I'll explain it briefly:
The code loops through the contents of
note
element by element. If the element (word) is found inmagazine
it is removed from there and allowed through the filter function.The code then checks whether the same number of elements as the size of
note
was returned after filtering to verify whether or not to return 'Yes' or 'No'.