Skip to main content

Posts

how to create a hashtable in typescript which can store both number and string using generic code

running sample https://stackblitz.com/edit/typescript-2zlayw code=> //hash node class   HashNode < T , U > {     key : T     value : U      constructor ( _key : T , _value : U )      {          if ( typeof  _key === "object" )            throw   new   Error ( "object as key not allowed" )          this . key = _key ;          this . value = _value ;      }      //get key      public  getKey ()      {         return   this . key ;      }      //get value   ...

Different methods to copy in C++ STL and its uses with code

// //   main.cpp //   Exp // //   Created by Manish on 07/11/19. //   Copyright © 2019 Manish. All rights reserved. // #include <iostream> #include <vector> #include <algorithm> using namespace std ; int main( int argc, const char * argv[]) {     //1     //copy**************************************************     vector < string > sourceA={ "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" };     vector < string > dest={ "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" };     //copy a to d and replace A to D in dest     copy (sourceA. begin (), sourceA. begin ()+ 4 , dest. begin ());          for ( auto x:dest)     {         cout <<x<< endl ;     }               cout << "-------------------...

INSERTION SORT IN C++ ( PART1 OF SORTING ALGORITHMS)

// //   main.cpp //   Exp // //   Created by Manish on 07/11/19. //   Copyright © 2019 Manish. All rights reserved. // #include <iostream> #include <vector> using namespace std ; vector < int > insertionSort( vector < int > &myVector) {    //left index     int leftIndex;     //key element     int key;     //loop from first index to length-1     for ( int i= 1 ;i!=myVector. size ();i++)     {         //store first element in inside key         key=myVector[ i ];         leftIndex=i- 1 ;         //swap element until left is greator than right and leftindex >=0         while (leftIndex>= 0 && myVector[ leftIndex ]>key) {                     ...

Just little basic about recursion dynamic programming and memorization using some simple example in javascript

working sample https://stackblitz.com/edit/js-h3abpu recursion  and memorization these three are the 2 important pillar of computer programming when you are dealing with big task and you want to break your task to smaller parts. let take a example a simple example you have a array and you want to find to maximum value form that array. so let try to solve this problem using recursion //Find a maximum value in a unsorted array //here how i can find max item from a array using recursion function findMax ( arr , len ) { //if length is 1 return first item if ( len == 1 ) { return arr [ 0 ]; } //else recursively search the next maximum item in the array return Math . max ( arr [ len - 1 ], findMax ( arr , len - 1 )) }   now find the minimum item in array function findMin ( arr , len = arr . length ) { if ( len == 1 ) { return arr [ 0 ]; } return Math . min ( arr [ len - 1 ], findMin ( arr , ...
working link  https://stackblitz.com/edit/js-wnzbgw rotate a array (right direction) k times //Right Rotation of a Array -----------------------using O(n) space and O(n) time complexity var myArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 ]; function RotationRightFirstMethod ( no_of_times ) { var newArray =[]; var t = myArray . length ; for ( var i = 0 ; i < t ; i ++) { newArray [( i + no_of_times )% t ]= myArray [ i ]; } return newArray ; } console . log ( "result 1" , RotationRightFirstMethod ( 4 )); //lets try using some my own method ---------- var myArray2 =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 ]; function RotationRightSecondMethod ( n ) { var firstArray =[]; var secondArray =[]; for ( var i = 0 ; i < myArray2 . length - n ; i ++) { firstArray . push ( myArray2 [ i ]) } for ( var i = myArray2 . length - n ; i < myArray2 . length ; i ++) { secondArray . push ( myArray2 [ i ]); } return secondArray . c...

polyfill for map and filter method in javascript

working link==> https://stackblitz.com/edit/js-wpw67a //check out filter map and reduce once //create your own map function or polyfill for map //map callback accept three parameter one value second index and third one is a current array //create a polyfill for map function Array . prototype . myMap = function ( callBack ) { if ( typeof callBack != "function" ) { throw new TypeError (); } var newArray =[]; for ( var i = 0 ; i < this . length ; i ++) { //this is current Array //i is index //this[i] is current item newArray . push ( callBack . apply ( null ,[ this [ i ], i , this ])); } return newArray ; } var myArray =[ 1 , 2 , 3 , 4 , 5 ]; var newArray = myArray . myMap (( value , index )=>{ return value * index ; }) console . log ( newArray ); //now polyfill for filter which accept three parameter one value second index and...

function composition (function programming) over inheritance javascript with example

working link https://stackblitz.com/edit/js-d57tvk more about https://www.youtube.com/results?search_query=functional+programming+vs+object+oriented+javascript a better link https://www.youtube.com/watch?v=7HolHe7Gqbw&t=263s example :- //function composition (function programming) over inheritance //create some global function every thing except number and string are object in javascript //@function showName---------------------------- const showName =( state )=>({ getfullName () { return state . name + " " + state . last ; } }); //@function showSalary---------------------------- const showSalary =( state )=>( { bonus : 800 , getSal () { return state . sal * 12 + this . bonus ; } } ) //@function what emp do const WhatHeDo =( state )=>( { getType () { switch ( state . type ) { case "it" : ...

creating a dynamic tabbar in reactjs

working link https://stackblitz.com/edit/react-scyhqh import React , { Component } from 'react' ; import { render } from 'react-dom' ; import Hello from './Hello' ; import './style.css' ; function TabButton ( props ) { return < button className = "button" onClick ={()=>{ if ( props . onClick != null ) { props . onClick ({ label : props . label }); } }}>{ props . label }</ button > } class App extends Component { constructor () { super (); this . currentPage = 0 ; this . totalPage = 4 ; this . buttonData =[ { label : "manish1" }, { label : "sachin2" }, { label : "deepak3" }, { label : "sanjay4" }, { label : "manish21" }, { label : "sachin22" }, { label : "de...