Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 2.Algorithms/homework2.js
Original file line number Diff line number Diff line change
@@ -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);