javascript ECMAScript中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ECMAScript中相关的知识,希望对你有一定的参考价值。

// Output call stack of a function
console.trace(); 
 
// Profiling
function thisNeedsToBeProfiled() {
  console.profile("thisNeedsToBeProfiled()");
  // body of a function
  console.profileEnd();
}
 
// HeapSize
console.memory 
 
// Output in table
console.table(array)
 
// Execution time
console.time()
doSomethin();
console.timeEnd();
 
// Performance
var t0 = performance.now();
doSomethin();
var t1 = performance.now();
console.log("Call to doSomething" + (t1 - t0) + " milliseconds.");
// Merge Sort Implentation (Recursion)
function mergeSort (unsortedArray) {
  // No need to sort the array if the array only has one element or empty
  if (unsortedArray.length <= 1) {
    return unsortedArray;
  }
  // In order to divide the array in half, we need to figure out the middle
  const middle = Math.floor(unsortedArray.length / 2);

  // This is where we will be dividing the array into left and right
  const left = unsortedArray.slice(0, middle);
  const right = unsortedArray.slice(middle);

  // Using recursion to combine the left and right
  return merge(
    mergeSort(left), mergeSort(right)
  );
}

// Merge the two arrays: left and right
function merge (left, right) {
  let resultArray = [], leftIndex = 0, rightIndex = 0;

  // We will concatenate values into the resultArray in order
  while (leftIndex < left.length && rightIndex < right.length) {
    if (left[leftIndex] < right[rightIndex]) {
      resultArray.push(left[leftIndex]);
      leftIndex++; // move left array cursor
    } else {
      resultArray.push(right[rightIndex]);
      rightIndex++; // move right array cursor
    }
  }

  // We need to concat here because there will be one element remaining
  // from either left OR the right
  return resultArray
          .concat(left.slice(leftIndex)
          .concat(right.slice(rightIndex));
}

以上是关于javascript ECMAScript中的主要内容,如果未能解决你的问题,请参考以下文章

Javascript与ECMAScript

赶上 ECMAScript 潮流:用现代 JavaScript 编程

JavaScript SHAREPOINT 2010使用ECMASCRIPT从列表中读取

213期ECMAScript 潮流:用现代 JavaScript 编程

javascript ECMAScript 6中符号的用途是啥? [复制]

ECMAScript和JavaScript及TypeScript