Skip to content

Instantly share code, notes, and snippets.

@sshehrozali
Created April 17, 2022 09:50
Show Gist options
  • Save sshehrozali/588f0e71a0612a6a92648484623423f1 to your computer and use it in GitHub Desktop.
Save sshehrozali/588f0e71a0612a6a92648484623423f1 to your computer and use it in GitHub Desktop.
Coding problem given to me during my Technical Round @munchies, Pakistan
// Given an array of numbers, check if sum of two equals to target or not
// Example [4, 7, 8, 9], target = 11
// True
// Array of sequence number n
let array = [4, 7, 8, 9];
// Constant Target to find
const target = 11;
// Iterate through whole array
for (let i = 0; i < array.length; i++) {
// Check each member of the array
for (let j = 0; j < array.length; j++) {
// Calculate the validation
let validate = array[i] + array[j];
// Check if it matches the target
if (validate == target) {
// Define the string
let string = "Found " + array[i] + " + " + array[j] + " = " + target;
console.log(string); // Display the result
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment