I wanna write a function that receive two parameter that first one is an array and the second is an integer; So I wanna return two element of the array that their sum be equal the second function's parameter. For example in this case findSum([1,2,3,5], 5) my function will return 2 and 3 that their sum being 5. I wrote a function but I think it can be better with another optimized coding.
function findSum(arr, sum){
for(element of arr) {
const first_element = element;
for(innerElement of arr){
if((innerElement !== first_element) && (innerElement + element === sum) )
return {first_element, innerElement}
}
}
}