Skip to content

Instantly share code, notes, and snippets.

@fmacedoo
Created January 26, 2023 22:14
Show Gist options
  • Save fmacedoo/4280804b089783298e276c83c36568d8 to your computer and use it in GitHub Desktop.
Save fmacedoo/4280804b089783298e276c83c36568d8 to your computer and use it in GitHub Desktop.
Problem 0001 [EASY]
// Given a list of numbers and a number k, return whether any two numbers from the list add up to k.
// For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
// Bonus: Can you do this in one pass?
function problem(numbers, k) {
// TODO: drop here you logic to solve this problem!
return false;
}
const testcases = [
{
numbers: [10, 15, 3, 7],
k: 17,
expect: true,
},
{
numbers: [5, 56, 24, 3],
k: 17,
expect: false,
},
{
numbers: [10, 4, 6, 1],
k: 11,
expect: true,
},
{
numbers: [37, 74, 70, 86],
k: 144,
expect: true,
},
];
for (const testcase of testcases) {
const result = problem(testcase.numbers, testcase.k);
const pass = result === testcase.expect;
console.log(
`[${pass ? 'PASS ✅' : 'FAILED ⛔'}] numbers: ${testcase.numbers} \ k: ${testcase.k} \ expect: ${testcase.expect} \ result: ${result}`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment