// 求和问题,给定数组,求和是N的两个数组合
function sumN (N, nums) {
let answers = [], tmpDic = {}
for(let index in nums) {
if(nums[index] < N) {
if(tmpDic[nums[index]]) tmpDic[nums[index]] ++
else tmpDic[nums[index]] = 1
let key = N - nums[index]
if(tmpDic[key] == 1) {
answers.push([nums[index], key])
}
}
}
console.log(answers)
}
sumN(15, [8, 7, 2, 4, 6, 9, 1, 5, 8, 3, 10, 4, 11, 13, 14])