function towSum(nums, target) { let i = 0; let j = nums.length - 1; while (i <= j) { if (nums[i] + nums[j] == target) { let ans = "[" + i + "," + j + "]"; //var temp = [i]; //temp.push(j); //return temp; return ans; } else if (nums[i] + nums[j] < target) i++; else if (nums[i] + nums[j] > target) j--; } return -1; } const nums = [1, 2, 3, 4, 5, 6]; const target = 11; console.log(towSum(nums, target));