Other favourite plugins:
- Bracket Pair Colorizer
- Indent Rainbow
- Auto Rename Tag
What is your first VS Code plugin? Comment below.
function quickSort(arr, start, end) {
// Stop the recursion when the start equal or smaller to the end
if (start >= end) {
return ;
};
// Here is the magic happen
let pivotIndex = partition(arr, start, end);
// Recursion - quick sort the left part
quickSort(arr, start, pivotIndex - 1);
// Recursion - quick sort the right part
quickSort(arr, pivotIndex + 1, end);
}
function partition (arr, start, end) {
let pivotIndex = start; // Pivot location
let pivotValue = arr[end]; // Use the last number
for (let i=start; i<end; i++) {
// Move number that smaller than pivot value to the front.
// Update pivot index
if (arr[i] < pivotValue) {
// Move to front
swap(arr, i, pivotIndex);
pivotIndex++;
}
}
// Swap the pivot value to correct location
swap(arr, end, pivotIndex);
return pivotIndex;
}
function swap(arr, a, b) {
let temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
let arr = [2 ,1, 4, 5, 3, 6, 6, 8, 1, 3];
quickSort(arr, 0, arr.length - 1);
let items = [1,2,3,5,4];
function bubbleSort(p_val){
let sorted = p_val;
for (let i=0, x=p_val.length; i<=x; i++){
let isSwapRequired = false;
for(let j=0; j<=x-i-1; j++){
// compare items and only swap them if the second one's smaller
if (sorted[j] > sorted[j+1]) {
isSwapRequired = true;
let first = sorted[j];
let second = sorted[j+1];
sorted[j+1] = first;
sorted[j] = second
}
}
// IF no two elements were swapped by inner loop, then break
if (!isSwapRequired) { break; };
}
return sorted;
}
document.write(bubbleSort(items));
The best case is when the array is already sorted, and worst case is the array is reverse sorted.// Parameter: A string.
// Return: Last character of the string.
function reverseString(p_val){
// Get the string's length
var length = p_val.length;
// Get the last character
var lastchar = p_val.charAt(length - 1);
if (length == 1) {
// Return the last char
return lastchar;
} else {
// Run the recursion
return lastchar + reverseString(p_val.substring(0,length - 1))
}
}
var ARMORY = (function(){
// Private
var weaponList = [ * List of weapon object * ];
var removeWeapon = function(...){};
var replaceWeapon = function(...){};
// Public
return{
makeArmorRequest: function(...){}
}
});
Now you can create multiple instances:var army1 = new ARMORY();
var army2 = new ARMORY();
<script src"javascript/like_button.js"></script>
const employees = ['Simon','Adam','John'];
console.log(Object.getPrototypeOf(employees));
Output: