JSFiddle - React, Tailwind, and code Playground
by brigand
JavaScript
const arr = [33, 21, 19, 4, 11, 44, 18, 12, 9];
const target = 20;
const has_pair = (arr, target) => {
const seen = new Set();
return arr.some((item) => {
if (seen.has(target - item)) {
return true;
} else {
seen.add(item);
}
});
};
console.log(has_pair(arr, target));