Day 22A of Scrimba JavaScriptmas — Sum of Two

const nums1 = [1, 2, 3];
const nums2 = [10, 20, 30, 40];
const value = 42;
function sumOfTwo(nums1, nums2, value) {
// write code here.
const values = nums1.concat(nums2);
const lastValue = value;

let hashTable = {};
values.forEach((value, index) => (hashTable[value] = index));

let twoSum = function(nums, target){
numsIndexes = {};

for(let i=0; i<nums.length; i++){
let currentDiffernce = target - nums[i];

if(numsIndexes[currentDiffernce] !== undefined && numsIndexes[currentDiffernce !== 1]){
return false
}else{
return true
}
}
}

return twoSum(values, lastValue)
}
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Output: Because nums[0] + nums[1] == 9, we return [0, 1].

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store