Created
April 17, 2022 09:50
-
-
Save sshehrozali/588f0e71a0612a6a92648484623423f1 to your computer and use it in GitHub Desktop.
Coding problem given to me during my Technical Round @munchies, Pakistan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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