JavaScript using object as map
\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findPairs = function(nums, k) {\n  if (!nums.length || k < 0) return 0;\n 
```\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findPairs = function(nums, k) {\n  if (!nums.length || k < 0) return 0;\n  const map = {};\n  let counter = 0;\n  nums.forEach(n => {\n    map[n] = (map[n] || 0) + 1;\n  });\n  Object.keys(map).forEach(key => {\n    if (k === 0) {\n      if (map[key] > 1) counter++;\n    } else if (map[parseInt(key) + k]) {\n      counter++;\n    }\n  });\n  return counter;\n};\n```
['JavaScript']