title: Two-sum Leetcode explanation, Hashmap, Javascript
body: <p>Im just wondering who can explain the algorithm of this solution step by step. I dont know how hashmap works. Can you also give a basic examples using a hashmap for me to understand this algorithm. Thank you!</p>
  
  <pre><code>var twoSum = function(nums, target) {
    let hash = {};
  
    for(let i = 0; i &lt; nums.length; i++) {
      const n = nums[i];
      if(hash[target - n] !== undefined) {
        return [hash[target - n], i];
      }
      hash[n] = i;
    }
    return [];
  }
  </code></pre>