Skip to content

Instantly share code, notes, and snippets.

@hroman-codes
Created September 29, 2020 19:41
Show Gist options
  • Save hroman-codes/d44858635ef62ef55da1d308e1606b5d to your computer and use it in GitHub Desktop.
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]
// 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