Hey! Great work, just a few things:
There's a small but important error in your second for loop: j is set to 1, it should be i+1. This way you're always comparing i with the element that follows. The way it is now, every time i increases, j is set back to 1.
Once your function finds a match (sum == targetSum), you're pushing an array into the indicesTracker array, so your function is returning a nested array: [[i, j]]. You can simply push the elements themselves.
Your function also keeps going even after it finds a match. As it is now, given targetSum = 9, and array = [1, 7, 3, 2, 6], your function will return [1, 3, 2, 4].
Thank you so much for the clear explanation Claire! Really really appreciate it! It all makes more sense now! I've also started using the link you suggested and is trying to understand how it works ! :D
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.