JoBat update

A Virtual World of Infotainment :)

Merge Sort

Youtube Link :

https://www.youtube.com/playlist?list=PL08k51bYn7cCKCol9q-wien5l64vvF0eQ

Code : 


 1 
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function mergeArray(arr1,arr2){
    let result=[];
    let i=0;
    let j=0;
    while(i<arr1.length && j<arr2.length){
        if(arr1[i]<arr2[j]){
            result.push(arr1[i]);
            i++;
        }
        else{
            result.push(arr2[j]);
            j++;
        }
    }
    while(i<arr1.length){
        result.push(arr1[i]);
        i++;
    }
    while(j<arr2.length){
        result.push(arr2[j]);
        j++;
    }
    return result;
 }

function mergeSort(array){
    if(array.length<=1)
        return array;
    let mid   = Math.floor(array.length/2);
    let left  = mergeSort(array.slice(0,mid));
    let right = mergeSort(array.slice(mid));
    return mergeArray(left,right);
}
mergeSort([6,3,2,9,1,23,65,34]);
Newer Posts Older Posts Home

SUBSCRIBE & FOLLOW

POPULAR POSTS

  • Sketch Movie Review
  • Thaana Serndha Kootam (aka) TSK Movie Review
  • Suriya 37 Confirmed!
  • Mersal Movie Review
  • Tyrese Gibson Threatens To Quit FF Franchise..!
  • Windows 10 May 2020 Update How to Download it and its features
  • Square Matrix-Corner Elements Sum
  • Middlewares in Express JS
  • Aval Movie Review
  • JBM awards 2k18

Categories

  • Awards 4
  • Code 23
  • Review 19
  • sport 1
  • Tech 20
  • Update 19

Contact Form

Name

Email *

Message *

  • ►  2020 (3)
    • ►  July (1)
    • ►  May (2)
  • ▼  2019 (8)
    • ►  October (1)
    • ▼  July (1)
      • Merge Sort using JavaScript
    • ►  June (1)
    • ►  February (1)
    • ►  January (4)
  • ►  2018 (52)
    • ►  October (3)
    • ►  September (3)
    • ►  August (2)
    • ►  July (3)
    • ►  June (5)
    • ►  May (1)
    • ►  April (10)
    • ►  March (19)
    • ►  February (1)
    • ►  January (5)
  • ►  2017 (19)
    • ►  December (3)
    • ►  November (8)
    • ►  October (8)

Search This Blog

Powered by Blogger.

Report Abuse

HOME

  • HOME
  • Code Block
  • Tech World
  • How is it?
  • What's Up?
  • JoBatMovie_Awards
  • Sports Block
  • Privacy Policy

JoBatMovie Awards

  • Home
  • JoBatMovie Awards
  • Home

Featured post

JBM awards 2k18

JoBat Updates

Designed by OddThemes | Distributed by Gooyaabi Templates