Setting up
Jest
npm install -g jest
npm root -g
# Run test
jest test.js --watch
debugger
function funcName() {
//
debugger;
//
}
node inspect test.js
# continue
debug> c
# enter repl to check the variables
debug> repl
Null vs Undefined
let test;
console.log( test ); // undefined
test = null
console.log( test ); // null
console.log( 1 + null ); // 1
console.log( 1 + undefined ); // NaN
console.log( null == undefined ); // true
console.log( null === undefined ); // false
Reverse String
function reverse(str) {
}
Memoization - Fibonacci
function memoize(fn) {
const cache = {};
return function (...args) {
if (cache[args]) {
return cache[args];
}
const result = fn.apply(this, args);
cache[args] = result;
return result;
};
}
function slowFib(n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
const fib = memoize(slowFib);
Top comments (0)