Skip to content

Instantly share code, notes, and snippets.

@umairqazi523
Created September 17, 2020 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umairqazi523/c3178870111f4372f3c88845b7226c7b to your computer and use it in GitHub Desktop.
Save umairqazi523/c3178870111f4372f3c88845b7226c7b to your computer and use it in GitHub Desktop.
class TwoSum {
constructor(_inputArray, _targetValue) {
this.inputArray = _inputArray;
this.targetValue = _targetValue
this.outputArray = []
}
get() {
let i, j;
for (i = 0; i < this.inputArray.length; i++) {
for (j = 0; j < this.inputArray.length; j++) {
if (i == j) {
continue;
}
if (this.inputArray[i] + this.inputArray[j] == this.targetValue) {
this.outputArray = [i, j];
break;
}
}
}
console.log(this.outputArray);
return this.outputArray;
}
}
let twoSum = new TwoSum([2, 5, 9, 1, 3, 7, 2], 4);
twoSum.get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment