#Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution.

##Example:

```
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
```

Here is my solution.

```
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
return nums.reduceRight((ans,val,idx,arr)=>{
const remainder = target - val;
const idx2 = arr.indexOf(remainder);
return (idx !== idx2 && idx2 !== -1)?[idx, idx2]: ans;
},[]);
```

I’m thinking this is the best answer because O(n) but would like feedback.