LeetCode #1 - Two Sum (JavaScript)

The solution for Two Sum problem is pretty much straightforward - we need to create a hash for every iteration and just check if member of a hash exists if we subtract current element's value from a target.

const twoSum = (n, t) => {
    const h = {};
    
    for (let i = 0; i < n.length; i++) {
        const val = n[i];

        if (Object.prototype.hasOwnProperty.call(h, t - val)) {
            return [h[t - val], i];
        } else {
            h[val] = i;
        }
    }
}