Here is my code in JS:

```
var twoSum = function(nums, target) {
var tempMap ={};
for(var i = 0; i< nums.length; i++){
tempMap[nums[i]] = true;
}
for(var i = 0; i< nums.length; i++){
if(target-nums[i] !== nums[i] && tempMap[target-nums[i]]){
return [nums[i], target - nums[i]];
}
}
};
```

However, I got wrong answer:

Input: [3,2,4], 6 Output: [2,4] Expected: [2,3]

[2,3] shouldn't be the right answer. Can someone help me figure out? Thanks.