Skip to content
Merged
Show file tree
Hide file tree
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
Empty file added DataStructures/ArrayList.js
Empty file.
10 changes: 10 additions & 0 deletions Interface/mapInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let animals = new Map([
[1, "panda"],
[2, "cat"],
[3, "dog"]
]);

animals.set(4, "bear");
console.log(animals.get(1));
console.log(animals.has(4));
console.log(animals.keys());
12 changes: 12 additions & 0 deletions Interface/setInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let animal = new Set();
animal.add("panda");
animal.add([1, 2, 3]);
console.log(animal.size);
animal.forEach(a => {
console.log(a);
});
//animal.delete("panda");
console.log(animal);
console.log(animal.keys());
animal.clear();
console.log(animal);
26 changes: 26 additions & 0 deletions Sorting/median.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function median(left, right) {
let result = [];

while (left.length && right.length) {
if (left[0] <= right[0]) {
result.push(left.shift());
} else {
result.push(right.shift());
}
}

while (left.length) {
result.push(left.shift());
}
while (right.length) {
result.push(right.shift());
}
let length = result.length;
if (length % 2 == 0) {
return [result[length / 2 - 1], result[length / 2]];
} else {
return result[Math.floor(length / 2)];
}
}

console.log(median([1, 5, 8, 9], [2, 3, 7, 10]));
2 changes: 1 addition & 1 deletion Sorting/mergeSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function stitch(leftVal, rightVal) {
// console.log(leftVal, rightVal);
let results = [];
while (leftVal.length && rightVal.length) {
if (leftVal[0] < rightVal[0]) {
if (leftVal[0] <= rightVal[0]) {
results.push(leftVal.shift());
} else {
results.push(rightVal.shift());
Expand Down
20 changes: 20 additions & 0 deletions Sorting/quickSort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function quickSort(numbers) {
let l = numbers.length;
if (l < 2) {
return numbers;
} else {
let pivot = numbers.pop();
let left = [];
let right = [];
while (numbers.length) {
if (pivot > numbers[0]) {
left.push(numbers.shift());
} else {
right.push(numbers.shift());
}
}
return [].concat(quickSort(left), pivot, quickSort(right));
}
}

console.log(quickSort([10, 8, 2, 1, 6, 3, 9, 4, 7, 5]));