Skip to content

Instantly share code, notes, and snippets.

View AnkitMaheshwariIn's full-sized avatar

Ankit Maheshwari AnkitMaheshwariIn

View GitHub Profile
@AnkitMaheshwariIn
AnkitMaheshwariIn / index.html
Last active August 1, 2022 00:28
Create a Single Page Website using Node.js and Express.js
<!DOCTYPE html>
<html lang="en">
<title>W3.CSS Template</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {font-family: "Lato", sans-serif}
@AnkitMaheshwariIn
AnkitMaheshwariIn / home.page.component.ts
Last active April 5, 2022 02:26
create an 'Observable'. Use Async-Pipe
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs'
@Component({
selector: 'app-home',
templateUrl: './home.page.component.html',
styleUrls: ['./home.page.component.css'],
})
// we must 'implements OnInit' to use 'OnInit'
export class HomePageComponent implements OnInit {
@AnkitMaheshwariIn
AnkitMaheshwariIn / find-factorial.js
Last active March 31, 2022 17:26
program to find the factorial of a number
// program to find the factorial of a number
function findFactorial(num) {
// if number is 0
if (num === 0) {
return 1
} else {
// if number is positive,
// multiply number with response of function findFactorial(num - 1),
// having argument one less than num
@AnkitMaheshwariIn
AnkitMaheshwariIn / count-down.js
Last active March 30, 2022 13:01
unction to count down numbers to 1 in JavaScript
// function to count down numbers to 1
function countDownFunc(number) {
// display the number
console.log(number);
// decrease the number value by 1
const newNumber = number - 1;
// check condition, the countDownFunc will call itself till the value of newNumber becomes 0
@AnkitMaheshwariIn
AnkitMaheshwariIn / recursion-in-javascript.js
Created March 30, 2022 11:47
What is the Recursion technique
function recursiveFunction() {
// other code..
// calling itself, means calling recursive function
// from within recursiveFunction
recursiveFunction();
// other code..
}
@AnkitMaheshwariIn
AnkitMaheshwariIn / linear-search-javascript-array
Last active March 24, 2022 11:36
Code to search an item from an array using linear search
/* RUN THIS CODE AND OPEN YOUR CONSOLE TO SEE THE OUTPUT */
// Code to search an item from an array using linear search
// declare a function which will take two arguments: array and itemToSearch
const doLinearSearch = (arr, itemToSearch) => {
// iterate using for loop, where i is index and elem is each item
for (const [i, elem] of arr.entries()) {
if (elem === itemToSearch) {
// return index, if elem matched with item to search
@AnkitMaheshwariIn
AnkitMaheshwariIn / deletion-of-last-element
Created March 24, 2022 06:09
Code to delete last element from an array
/* RUN THIS CODE AND OPEN YOUR CONSOLE TO SEE THE OUTPUT */
// Code to delete last element from an array
// declare an array
arr = [10, 20, 30, 40, 50, 60]
console.log("To print elements before deletion")
for (i = 0; i < arr.length; i++) {
console.log(`Element at index ${i} is ${arr[i]}`)
@AnkitMaheshwariIn
AnkitMaheshwariIn / deletion-of-first-element
Created March 24, 2022 06:06
Code to delete first element from an array
/* RUN THIS CODE AND OPEN YOUR CONSOLE TO SEE THE OUTPUT */
// Code to delete first element from an array
// declare an array
arr = [10, 20, 30, 40, 50, 60]
console.log("To print elements before deletion")
for (i = 0; i < arr.length; i++) {
console.log(`Element at index ${i} is ${arr[i]}`)
@AnkitMaheshwariIn
AnkitMaheshwariIn / deletion-of-any-element
Created March 24, 2022 06:00
Code to delete element at a specific position from an array
/* RUN THIS CODE AND OPEN YOUR CONSOLE TO SEE THE OUTPUT */
// Code to delete element at a specific position from an array
// declare an array
arr = [10, 20, 30, 40, 50, 60]
console.log("To print elements before deletion")
for (i = 0; i < arr.length; i++) {
console.log(`Element at index ${i} is ${arr[i]}`)
@AnkitMaheshwariIn
AnkitMaheshwariIn / print3dArray.js
Last active March 23, 2022 12:22
print3dArray
/* RUN THIS CODE AND OPEN YOUR CONSOLE TO SEE THE OUTPUT */
const print3dArray = (arr3d) => {
console.log("I am in 3d array visualization")
for (let i = 0; i< arr3d.length; i ++) {
for (let k = 0; k< arr3d[i].length; k ++) {
for (let m = 0; m< arr3d[i][k].length; m ++) {
console.log(`value at i[${i}] k[${k}] m[${m}] is ${arr3d[i][k][m]}`)
}
}