From 6eea5672fb7116d61587b48d8d74e41e2bc36527 Mon Sep 17 00:00:00 2001 From: kameliabouamara <74714311+kameliabouamara@users.noreply.github.com> Date: Mon, 14 Mar 2022 15:31:30 +0100 Subject: [PATCH 1/3] Add files via upload --- homework2.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 homework2.js diff --git a/homework2.js b/homework2.js new file mode 100644 index 0000000..649f379 --- /dev/null +++ b/homework2.js @@ -0,0 +1,35 @@ +// Remove a specific Element from an array ( no predefined functions allowed)// + +var array = [5, 8, 9, 33, 7]; +const specificElement = 9; +var i, j, k; +var newArray = []; +j = 0; +var N = array.length; +for (i = 0; i < N; i++) { + for (j = i + 1; j < N; j++) { + if (array[i] == specificElement) { + array[i] = array[j]; + N--; + + } + } +} + +console.log("our sorted array:" + array); + +// Remove Duplicates from Sorted Array( no predefined functions allowed) +arr = [5, 48, 5, 5]; +k = 0; +for (i = 0; i < arr.length; i++) { + for (j = i + 1; j < arr.length; j++) { + if (arr[i] != arr[j]) { + newArray[k] = arr[j]; + newArray.lentgh++; + + } + + } + k++; +} +console.log("our sorted array is:" + newArray); \ No newline at end of file From c827dd26e67a4f4631183251f4ea3e7e19bf8655 Mon Sep 17 00:00:00 2001 From: kameliabouamara <74714311+kameliabouamara@users.noreply.github.com> Date: Mon, 14 Mar 2022 15:32:07 +0100 Subject: [PATCH 2/3] Delete homework2.js --- homework2.js | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 homework2.js diff --git a/homework2.js b/homework2.js deleted file mode 100644 index 649f379..0000000 --- a/homework2.js +++ /dev/null @@ -1,35 +0,0 @@ -// Remove a specific Element from an array ( no predefined functions allowed)// - -var array = [5, 8, 9, 33, 7]; -const specificElement = 9; -var i, j, k; -var newArray = []; -j = 0; -var N = array.length; -for (i = 0; i < N; i++) { - for (j = i + 1; j < N; j++) { - if (array[i] == specificElement) { - array[i] = array[j]; - N--; - - } - } -} - -console.log("our sorted array:" + array); - -// Remove Duplicates from Sorted Array( no predefined functions allowed) -arr = [5, 48, 5, 5]; -k = 0; -for (i = 0; i < arr.length; i++) { - for (j = i + 1; j < arr.length; j++) { - if (arr[i] != arr[j]) { - newArray[k] = arr[j]; - newArray.lentgh++; - - } - - } - k++; -} -console.log("our sorted array is:" + newArray); \ No newline at end of file From 82d2a77371b58f947e54f8c83f3800e3fb1029f8 Mon Sep 17 00:00:00 2001 From: kameliabouamara <74714311+kameliabouamara@users.noreply.github.com> Date: Mon, 14 Mar 2022 18:16:58 +0100 Subject: [PATCH 3/3] Add files via upload --- 2.Algorithms/homework2.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 2.Algorithms/homework2.js diff --git a/2.Algorithms/homework2.js b/2.Algorithms/homework2.js new file mode 100644 index 0000000..649f379 --- /dev/null +++ b/2.Algorithms/homework2.js @@ -0,0 +1,35 @@ +// Remove a specific Element from an array ( no predefined functions allowed)// + +var array = [5, 8, 9, 33, 7]; +const specificElement = 9; +var i, j, k; +var newArray = []; +j = 0; +var N = array.length; +for (i = 0; i < N; i++) { + for (j = i + 1; j < N; j++) { + if (array[i] == specificElement) { + array[i] = array[j]; + N--; + + } + } +} + +console.log("our sorted array:" + array); + +// Remove Duplicates from Sorted Array( no predefined functions allowed) +arr = [5, 48, 5, 5]; +k = 0; +for (i = 0; i < arr.length; i++) { + for (j = i + 1; j < arr.length; j++) { + if (arr[i] != arr[j]) { + newArray[k] = arr[j]; + newArray.lentgh++; + + } + + } + k++; +} +console.log("our sorted array is:" + newArray); \ No newline at end of file