24 Mar 2023

Return whether any Two Numbers in an Array add up to a Given Number

Taken from DailyCodingProblem:

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.


This is the answer I came up with:

// typescript

const solution = (numbers: Array<number>, k: number): boolean | any => {
  for (let num of numbers) {
    let rem = k - num
    return (numbers.includes(rem)) ? true : false


Solution tested in REPL:


Webmentions & Comments

Copyright © Paramdeo Singh · Built with Jekyll in 🇬🇾 · All Rights Reserved

[ this node is permanently morphing last updated on 28 May 2023 ]

Paramdeo Singh Guyana

Generalist. Edgerunner. Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs
Search Site

Results are from Blog, Link Dumps, and #99Problems