This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The sum of a range | |
| // The introduction of this book alluded to the following as a nice way to compute | |
| // the sum of a range of numbers: | |
| // console.log(sum(range(1, 10))); | |
| // Write a range function that takes two arguments, start and end , and returns | |
| // an array containing all the numbers from start up to (and including) end . | |
| // Next, write a sum function that takes an array of numbers and returns the | |
| // sum of these numbers. Run the example program and see whether it does | |
| // indeed return 55. | |
| // As a bonus assignment, modify your range function to take an optional third |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Minimum | |
| // The previous chapter introduced the standard function Math.min that returns | |
| // its smallest argument. We can build something like that now. Write a function | |
| // min that takes two arguments and returns their minimum. | |
| let minimum = (a, b) => { | |
| if (a < b) { | |
| return a | |
| } | |
| return b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findSolution(target) { | |
| function find(current, history) { | |
| if (current == target) { | |
| return history; | |
| } else if (current > target) { | |
| return null | |
| } else { | |
| return find(current + 5, `(${history} + 5)`) || | |
| find(current * 3, `(${history} * 3`) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| var x = 1 | |
| { | |
| let x = 2 // SyntaxError: Identifier 'x' has already been declared | |
| { | |
| function f(){ | |
| let x = 10 | |
| { | |
| var x = 20 // SyntaxError: Identifier 'x' has already been declared | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| let x = 1 | |
| { | |
| var x = 2 // SyntaxError: Identifier 'x' has already been declared | |
| { | |
| console.log('scope1 x = ', x); | |
| } | |
| console.log('scope2 x = ', x); | |
| } | |
| console.log('scope3 x = ', x); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| var x = 11 | |
| { | |
| let x = 10 | |
| { | |
| console.log('x (unknown) = ', x); // can you guess which x here? | |
| function f() { | |
| var a = 1 | |
| { | |
| var a = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| var x = 11 | |
| { | |
| var x = 10 | |
| { | |
| function f() { | |
| var a = 1 | |
| { | |
| var a = 2 | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| var x = 11 | |
| { | |
| var x = 10 | |
| { | |
| var x = 30; | |
| } | |
| console.log('x = ', x); // 30 | |
| } | |
| console.log('x = ', x); // 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MemDbKeyStore { | |
| constructor(name, store, initFn) { | |
| this.name = name | |
| this.store = store | |
| this.store[name] = {} | |
| if (typeof initFn === 'function') { | |
| initFn.call(this) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict' | |
| const fs = require('fs') | |
| const Table = require('./Table') // return class Table | |
| const Log = require('../../model/Log') // return call Log | |
| class DB { | |
| constructor() { | |
| this.pool = null | |
| this.tablesNameArray = [] |