Array Merge Sort Code in JavaScript function mergeSort(arr) { if (arr.length === 1) { return arr; } let mid = Math.floor(arr.length / 2); let leftArr = arr.slice(0,mid); let rightArr = arr.slice(mid); return merge(mergeSort(leftArr), mergeSort(rightArr)); } function megre (leftArr, rightArr) { let output = []; while (leftArr.length && rightArr.length) { if (leftArr[0] < rightArr[0]) { output.push(leftArr.shift()); [...]
Category Archives: Programming
Latest tutorials and tips for Programmers
Array Selection Sort Code in JavaScript function selectionSort(arr) { for (i =0; i<arr.length; i++) { indexSelection = i; for (j = i+1; j< arr.length; j++) { if (arr[j] < arr[indexSelection]) { indexSelection = j; } } //end for j if (indexSelection !== i) { let temp = arr[indexSelection]; arr[indexSelection] = arr[i]; arr[i] = temp; } […]
In the examples below we show how to implement Tree in Javascript including Breadth-First-Search and Depth-First-Search class Node { constructor(data) this.data = data; this.children = []; } addData(data) { this.children.push(new Node(data)); } removeData(data) { this.children = this.childern.filter((item)=> { return item.data !== data; }); } } class Tree { constructor(data) { this.root = data; } breadth_first_search(fn) […]
In the examples below we show useful javascript ES6 examples which are very valuable Including: Array Loop and Slice Regular expression, replaces all blanks & special characters Object Keys & Values Object Map Math Sign Palindrom example Every & Some Array map elements Array Foreach loop map, filter, find reverse String balanceParser example //////Loop and […]
In the example below we show how to call Post API using Axios asynchronously in React functional component. We utilise “useState” for creating a state variable pass its value to the post request: import React, { useState } from “react”; import axios from “axios”; const PostCreate = () => { const [title, setTitle] […]
For creating Http Get or Http Post Server using Nodejs (Not consuming Get or Post) Follow instructions below: First Create a Nodejs project by running: npm init -y Then install express and body-parser dependencies by running npm i express body-parser Now create and edit the index.js file and add below code […]