Hackerrank "Hash Tables: Ransom Note" Javascript Solution
Your solution may work for valid inputs, but you are not checking invalid input situations such as when the ransom letter contains more words than the ones in the magazine:

if(n &gt; m):
    throw new Error("ransom can not be written from magazine");


You can even go further by checking if the first line corresponds to what it pretends to be:

if (magazine.length !== m) 
    throw new Error("Wrong words number in magazine");
if (ransom.length !== n) 
    throw new Error("Wrong words number in ransom");


You can refactor the above conditions in one single line:

if(n &gt; m || agazine.length !== m || ransom.length !== n):
    throw new Error("Invalid input");