HackerRank "Ransom Note" challenge I have solved the Ransom Note
 challenge on HackerRank using JavaScript / ECMAScript 6. The challenge goes like this:

A kidnapper wrote a ransom note but is worried it will be traced back to him. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica of his ransom note. The words in his note are case-sensitive and he must use whole words available in the magazine, meaning he cannot use substrings or concatenation to create the words he needs.
Given the words in the magazine and the words in the ransom note, print Yes if he can replicate his ransom note exactly using whole words from the magazine; otherwise, print No.
Input Format
The first line contains two space-separated integers describing the respective values of (the number of words in the magazine) and (the number of words in the ransom note).
The second line contains space-separated strings denoting the words present in the magazine.
The third line contains space-separated strings denoting the words present in the ransom note.

My solution uses JavaScript Map objects (as suggested by the name of the challenge) and passes all tests with no timeouts. However, the solution itself is very literal, as in, it removes out each word in the ransom note from the magazine, unless the needed word is not available.
Note that the portion of code above ignore above this line is included with all challenges on the site, I left it in for the sake of completeness, so that anyone can copy-paste the whole block into the challenge page, if they wish.
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = &quot;&quot;;
var input_stdin_array = &quot;&quot;;
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split(&quot;\n&quot;);
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

const addValueOrIncrementCount = (value, map) =&gt; {
    let count = map.get(value)
    if (count) {
        map.set(value, ++count)
    } else {
        map.set(value, 1)
    }
    return count
}

const decrementCountIfPossible = (value, map) =&gt; {
    let count = map.get(value)
    if (!count) {
        return null
    } else {
        map.set(value, --count)
        return count
    }
}

const mapWordCounts = inputString =&gt; {
    const output = new Map()
    let occurrences
    for (let word of inputString.split(&quot; &quot;)) {
        addValueOrIncrementCount(word, output)
    }
    return output
}

const isRansomComposedFromMagazine = (ransom, magazine) =&gt; {
    const ransomMap = mapWordCounts(ransom)
    const magazineMap = mapWordCounts(magazine)
    let ransomWordFromMagazine
    for (let [word, count] of ransomMap.entries()) {
        while (count &gt; 0) {
            ransomWordFromMagazine = decrementCountIfPossible(word, magazineMap)
            if (ransomWordFromMagazine === null) {
                return false
            }
            count--
        }
    }
    return true
}

const getProgramInput = () =&gt; {
    const firstLine = readLine().split(' ')
    const magazineWordCount = parseInt(firstLine[0])
    const ransomWordCount = parseInt(firstLine[1])
    const magazine = readLine()
    const ransom = readLine()
    return {
        magazineWordCount: magazineWordCount,
        ransomWordCount: ransomWordCount,
        magazine: magazine,
        ransom: ransom
    }
}

const main = () =&gt; {
    const input = getProgramInput()
    console.log(isRansomComposedFromMagazine(input.ransom, input.magazine) ? &quot;Yes&quot; : &quot;No&quot;)
}
This code reads like a story, very nice, though at times a bit verbose.

The value returned from addValueOrIncrementCount is never used,
so you could drop the return statement.

decrementCountIfPossible returns a count, or null if the count cannot be decremented. It would be simpler and more natural to use if it returned boolean, because the returned count is not used anyway.

In mapWordCounts the variable occurrences is declared but never used.

Note that the map of word counts for ransomMap is not really necessary.
It's possible to simply loop over the words, updating the magazineMap,
and return false whenever the magazineMap doesn't have the required word.

You could use the || operator to simplify addValueOrIncrementCount:

const addValueOrIncrementCount = (value, map) =&gt; {
    map.set(value, 1 + (map.get(value) || 0))
}