Created
September 29, 2020 19:41
-
-
Save hroman-codes/d44858635ef62ef55da1d308e1606b5d to your computer and use it in GitHub Desktop.
π Live Code π» With Getroman [Two Number Sum Part 1] [Coding Challenge] [Javascript]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.algoexpert.io/questions/Two%20Number%20Sum | |
// Solution 1 | |
function twoNumberSum(array, targetSum) { | |
let arr = array; | |
let target = targetSum; | |
let pairedNumbers = []; | |
for (let i = 0; i < array.length; i++) { | |
let firstPointer = array[i]; | |
for (let j = i + 1; j < array.length; j++) { | |
let secondPointer = array[j]; | |
let addTwoNumbers = (firstPointer + secondPointer) | |
if (addTwoNumbers === target) { | |
pairedNumbers.push(firstPointer, secondPointer); | |
} | |
} | |
} | |
return pairedNumbers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment