JSFiddle - React, Tailwind, and code Playground

by Eugen Sunic

JavaScript

/* class Node {
  constructor(data) {
    this.data = data;
    this.left = null;
    this.right = null;
  }
}


class Tree {

  constuctor() {
    this.root = null;
  }

  insertNode(currentNode, newNode) {

    if (this.root === null) {
      this.root = new Node(3);
    }
    else{

       

  }


}
 */

arr1 = [1, 2, 6, 9, 11, 12, 15];
arr2 = [3, 5, 7, 11];

const resultArr = (function(arr1, arr2) {
  const arr = [];
  let i, j = 0;

  while (arr.length < (arr1.length + arr2.length)) {
    if (arr[i] <= arr[j]) {
      arr.push(arr[i])
      i++
    }
    if (arr[i] > arr[j]) {
      arr.push(arr[j])
      j++;
    }
  }
  return arr;

})(arr1, arr2)

console.log('merged array is:', resultArr);