From 122616424f03edfe6a3b6f6dee96c01026884e89 Mon Sep 17 00:00:00 2001 From: Amir-c-137 Date: Sun, 28 Apr 2024 16:57:01 +0330 Subject: [PATCH 1/3] add 3 function --- .DS_Store | Bin 0 -> 6148 bytes 40130212009/How To.txt | 3 +++ 40130212009/findMissingNumber.js | 13 +++++++++++++ 40130212009/maximumSubarraySum.js | 22 ++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 .DS_Store create mode 100644 40130212009/How To.txt create mode 100644 40130212009/findMissingNumber.js create mode 100644 40130212009/maximumSubarraySum.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b16c1c28a86745c56db6afc6a76af47821cf829b GIT binary patch literal 6148 zcmeHK&2G~`5T0#QvLQmsp-4Si;u;kvX%ST~u5k|>xYP&^fI?hHt%c)_;-o%Ak$i3+ z28k0dz$@??NW1`i`xDW)1i=MCwG+*J`!nP9e(T-M5E1idafhfyL>wxyb{FO+BKxJ@ zkPXw)1Tysum%7w}y7*bK3|I#Kbq3_#ZPFh0YlnKUKlbmz(^Q;Bsfgf#Fwl22XtGuzm#ZQZH!I&bnf;khWn>0mm`{lVmwtUVVZjh5v>^dcD+ z{nqvqkxd6lHk_z{Bp$-$^~)rSMd6EC7UwE9)E&IR8~xVKeBRyfww+$@@uKa_54vvK z+3P)8EE@d&gNKJF{dego6PN1!iQ&vra?juru25JryY#FRo{G_U>AK!?B!a;3z&~tV zeD%M4I{KA&{0H9S^WS}oi*S;qB0Iy#a<+9kqKtAXXh;*vS63K)M7!5kxZ-_FR<<&$ z3PTM#p<^%+&@OkV5w0Z9WW{d z0M^i~1Z9~^$QZ|= max) { + max = s; + } + let j = i + 1; + while (j < n) { + s += array[j]; + if (s >= max) { + max = s; + } + j++; + } + } + return max; +} + +let array = [1, 5, -1, -50, 3, 4, 7, -5]; +console.log(maximumSubarraySum(array)); From fb708d678052f48c03958d9389e3ce042da32701 Mon Sep 17 00:00:00 2001 From: Amir-c-137 Date: Sun, 28 Apr 2024 17:04:49 +0330 Subject: [PATCH 2/3] add next 3 functions --- 40130212009/mergeSortedArrays.js | 31 +++++++++++++++++++++++++++++++ 40130212009/removeDuplicates.js | 12 ++++++++++++ 40130212009/rotateArray.js | 18 ++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 40130212009/mergeSortedArrays.js create mode 100644 40130212009/removeDuplicates.js create mode 100644 40130212009/rotateArray.js diff --git a/40130212009/mergeSortedArrays.js b/40130212009/mergeSortedArrays.js new file mode 100644 index 0000000..46498b8 --- /dev/null +++ b/40130212009/mergeSortedArrays.js @@ -0,0 +1,31 @@ +function mergeSortedArrays(array1, array2) { + let counter1 = array1.length - 1; + let counter2 = array2.length - 1; + let counterMerge = array1.length + array2.length - 1; + + array1.length = counterMerge + 1; + + while (counter1 >= 0 && counter2 >= 0) { + if (array1[counter1] > array2[counter2]) { + array1[counterMerge] = array1[counter1]; + counter1--; + } else { + array1[counterMerge] = array2[counter2]; + counter2--; + } + counterMerge--; + } + + while (counter2 >= 0) { + array1[counterMerge] = array2[counter2]; + counter2--; + counterMerge--; + } + + return array1; +} + +let array1 = [3, 6, 8, 11]; +let array2 = [1, 4, 5, 7, 9, 10]; +mergeSortedArrays(array1, array2); +console.log(array1); diff --git a/40130212009/removeDuplicates.js b/40130212009/removeDuplicates.js new file mode 100644 index 0000000..bd611a4 --- /dev/null +++ b/40130212009/removeDuplicates.js @@ -0,0 +1,12 @@ +function removeDuplicates(array) { + let lenOfArray = 0; + for (let i = 0; i < array.length; i++) { + if (array[i] !== array[i - 1]) { + lenOfArray++; + } + } + return lenOfArray; +} + +let array = [1, 2, 2, 3, 3, 3, 4, 5]; +console.log(removeDuplicates(array)); diff --git a/40130212009/rotateArray.js b/40130212009/rotateArray.js new file mode 100644 index 0000000..2827ba3 --- /dev/null +++ b/40130212009/rotateArray.js @@ -0,0 +1,18 @@ +function rotateArray(arr, k) { + let n = arr.length; + k = k % n; + let rotatedArr = new Array(n); + for (let i = 0; i < k; i++) { + rotatedArr[i] = arr[n - k + i]; + } + + for (let i = k; i < n; i++) { + rotatedArr[i] = arr[i - k]; + } + + return rotatedArr; +} + +let array = [1, 2, 3, 4, 5]; +let k = 2; +console.log(rotateArray(array, k)); From cedbc417d6a1844ce9bfa351f8c5a41f20031cd0 Mon Sep 17 00:00:00 2001 From: Amir-c-137 Date: Sun, 28 Apr 2024 17:08:48 +0330 Subject: [PATCH 3/3] fix some stuff --- .DS_Store | Bin 6148 -> 6148 bytes 40130212009/.DS_Store | Bin 0 -> 6148 bytes Answers/How To.txt | 3 --- 3 files changed, 3 deletions(-) create mode 100644 40130212009/.DS_Store delete mode 100644 Answers/How To.txt diff --git a/.DS_Store b/.DS_Store index b16c1c28a86745c56db6afc6a76af47821cf829b..dc9ce7ede32164b6ebd47941118164a0f31b20da 100644 GIT binary patch delta 226 zcmZoMXfc=&!IhuHz`!8Dz`!W7S&(BTGdnks%gA6bS&c=W8AQjhG_qS5>L?f+SWe!@ zW?v5!%Sks3PR`FQ0IGxmplEKsi%U`t*f@?&tYx2^-XC=YN`qxmaL5#7U^A&KxF|0t zKQA4un}LCw!Gytp!H~fiNE%HxVC4e3jc>9To8V+umKn%yn|zs7ZL&1`n~4o2o7p-3 G@&f=j1v0n* delta 236 zcmZoMXfc=&!NXv{V8mbu#0Cron*}+RGc$5eUcf3P;+d15oRpKF#K6EHz`(#L0;EkR z&tP55Zfc~XU~FtLc@K;Is`Js<`t zE66}sHhBgczb!k1BSRiTF+({+Dnk)NF{-UVIR*y3|6l+%9ZmJ*U964B?%_w5pTYKf JGdss$egN-LI_m%c diff --git a/40130212009/.DS_Store b/40130212009/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0