Created
September 17, 2020 16:50
-
-
Save umairqazi523/c3178870111f4372f3c88845b7226c7b to your computer and use it in GitHub Desktop.
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
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