Find All Lonely Numbers in the Array LeetCode solution in JavaScript
1var findLonely = function (nums) {2let countMap = new Map();3let result = [];4for (let num of nums) {5countMap.set(num, (countMap.get(num) || 0) + 1);6}7for (let num of nums) {8if (9!countMap.has(num - 1) &&10!countMap.has(num + 1) &&11countMap.get(num) === 112) {13result.push(num);14}15}16return result;17};