Created
October 16, 2022 08:02
-
-
Save Merce0897/08e9d30dc46e8294313f7834770605e8 to your computer and use it in GitHub Desktop.
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
| const mergeAndSort = (array1: number[], array2: number[]): number[] => { | |
| array1.length += array2.length; | |
| for (let i = array1.length - array2.length; i < array1.length; i++) { | |
| array1[i] = array2[i - array1.length + array2.length]; | |
| } | |
| for (let i = 0; i < array1.length; i++) { | |
| for (let j = array1.length; j > i; j--) { | |
| if (array1[j] < array1[i]) { | |
| const temp = array1[i]; | |
| array1[i] = array1[j]; | |
| array1[j] = temp; | |
| } | |
| } | |
| } | |
| return array1; | |
| }; | |
| console.log(mergeAndSort([1, 3, 4, 5], [2, 6, 7, 8])); | |
| const findSum = (arr: number[], value: number): number[] => { | |
| let a: number = 0; | |
| let b: number = 0; | |
| for (let i = 0; i < Math.floor(arr.length / 2); i++) { | |
| for (let j = arr.length; j > Math.floor(arr.length / 2); j--) { | |
| if (arr[i] + arr[j] === value) { | |
| (a = arr[i]), (b = arr[j]); | |
| } | |
| } | |
| } | |
| return [a, b]; | |
| }; | |
| console.log(findSum([1, 21, 3, 14, 5, 60, 7, 6], 81)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment