Question: I have set of codes where i need to insert multiple rows in `MySQL` using procedures

```
<?php
$conn = new mysqli("localhost","root","","company");
$array_item = 'Array
(
    [0] => Array
        (
        [user_name] => VANITHA
        [adddress] => 
        [mobile_no] => 8877665544

        )

    [1] => Array
        (
       [user_name] => VANITHA1
        [adddress] => rere
        [mobile_no] => 8877665544
       )
);

';
$sql=mysqli_query($conn,"CALL addnew($array_item)");

```

procedures codes are as follows

```
 CREATE  PROCEDURE addnew(IN ArrayDemo VARCHAR(100))

    BEGIN  

    insert into geektable (user_name,adddress,mobile_no) 
                    values(user_name,adddress,mobile_no);  

    END

```

Answer: 
If you are fine with a function that just returns a pair of numbers (the first match so to speak) whose sum equals the targets value, this might be enough:

```js
function sumPair (arr, target) {
    while(arr.length) {
        let sum1 = arr.shift();
        let sum2 = arr.find(val => sum1 + val === target);
        if (sum2) return [sum2, sum1];
    }
    return null;
}

```
I changed for loop with forEach (more efficient) and there is no need for the copyArray array so I removed it. I also changed pop() with shift(), I think you want to shift the array and not pop-it (if I understand the task correctly).

```
function targetSum3(arr, target) {
        let newArr = [];
        arr.forEach(element => {
            let x = Math.abs(element - target); // calc x
            arr.shift(); // removes first element from arr (current element)
            if (arr.includes(x) && (arr.indexOf(x) != arr.indexOf(element))) {
                newArr.push(element);
                newArr.push(x);
                return;
            }
        });

    return newArr;
}

```