Write a function that takes a list of integers and returns the first pair of adjacent numbers that add up to a target sum. If no such pair exists, return -1.
Challenge 1.1: The Mysterious Case of the Missing Sums
You are a code ninja, on a mission to find the hidden sums.
Given a list of numbers, find the first pair that adds up to a target sum.
Solution:
function findPair(nums, target) {
for (let i = 0; i < nums.length - 1; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
return [nums[i], nums[j]];
}
}
}
return -1;
}