Permalink
Browse files

Refactored `var` into `const`/`let`, and removed a lot of semicolons

  • Loading branch information...
josdejong committed Jun 13, 2018
1 parent 934ea83 commit b3b96749bf904dd42660cd56af540a8fe1e5fdca
Showing 842 changed files with 12,281 additions and 12,894 deletions.
@@ -6,12 +6,11 @@ ideas and suggestions, and contribute to the code.

There are a few preferences regarding code contributions:

- Math.js follows the node.js code style as described
[here](https://github.com/felixge/node-style-guide).
- The code of math.js follows the JavaScript Standard Style as described on http://standardjs.com/.
- Make sure you properly unit test your changes.
- Before creating a pull request, run the unit tests to make sure they all pass.
- Only commit changes done in the source files under `lib`, not to the builds
which are located in the folder `dist`.
- Only commit changes done in the source files under `src`, not to the generated builds
which are located in the folders `dist` and `lib`.
- Send pull requests to the `develop` branch, not the `master` branch.

What can I do?
@@ -44,28 +44,28 @@ and supports

```js
// load math.js
var math = require('mathjs');
const math = require('mathjs')
// functions and constants
math.round(math.e, 3); // 2.718
math.atan2(3, -3) / math.pi; // 0.75
math.log(10000, 10); // 4
math.sqrt(-4); // 2i
math.pow([[-1, 2], [3, 1]], 2); // [[7, 0], [0, 7]]
math.derivative('x^2 + x', 'x'); // 2 * x + 1
math.round(math.e, 3) // 2.718
math.atan2(3, -3) / math.pi // 0.75
math.log(10000, 10) // 4
math.sqrt(-4) // 2i
math.pow([[-1, 2], [3, 1]], 2) // [[7, 0], [0, 7]]
math.derivative('x^2 + x', 'x') // 2 * x + 1
// expressions
math.eval('12 / (2.3 + 0.7)'); // 4
math.eval('12.7 cm to inch'); // 5 inch
math.eval('sin(45 deg) ^ 2'); // 0.5
math.eval('9 / 3 + 2i'); // 3 + 2i
math.eval('det([-1, 2; 3, 1])'); // -7
math.eval('12 / (2.3 + 0.7)') // 4
math.eval('12.7 cm to inch') // 5 inch
math.eval('sin(45 deg) ^ 2') // 0.5
math.eval('9 / 3 + 2i') // 3 + 2i
math.eval('det([-1, 2 3, 1])') // -7
// chaining
math.chain(3)
.add(4)
.multiply(2)
.done(); // 14
.done() // 14
```

See the [Getting Started](http://mathjs.org/docs/getting_started.html) for a more detailed tutorial.
@@ -2,11 +2,11 @@

// browserify benchmark/expression_parser.js -o ./benchmark_expression_parser.js

var assert = require('assert')
var Benchmark = require('benchmark')
var padRight = require('pad-right')
var math = require('../index')
var getSafeProperty = require('../lib/utils/customs').getSafeProperty
const assert = require('assert')
const Benchmark = require('benchmark')
const padRight = require('pad-right')
const math = require('../index')
const getSafeProperty = require('../lib/utils/customs').getSafeProperty

// expose on window when using bundled in a browser
if (typeof window !== 'undefined') {
@@ -17,19 +17,19 @@ function pad (text) {
return padRight(text, 40, ' ')
}

var expr = '2 + 3 * sin(pi / 4) - 4x'
var scope = {x: 2}
var compiled = math.parse(expr).compile(math, {})
const expr = '2 + 3 * sin(pi / 4) - 4x'
let scope = {x: 2}
const compiled = math.parse(expr).compile(math, {})

var sin = getSafeProperty(math, 'sin')
var pi = getSafeProperty(math, 'pi')
var compiledPlainJs = {
const sin = getSafeProperty(math, 'sin')
const pi = getSafeProperty(math, 'pi')
const compiledPlainJs = {
eval: function (scope) {
return 2 + 3 * ('sin' in scope ? getSafeProperty(scope, 'sin') : sin)(('pi' in scope ? getSafeProperty(scope, 'pi') : pi) / 4) - 4 * scope['x']
}
}

var correctResult = -3.878679656440358
const correctResult = -3.878679656440358

console.log('expression:', expr)
console.log('scope:', scope)
@@ -38,9 +38,9 @@ console.log('result:', correctResult)
assertApproxEqual(compiled.eval(scope), correctResult, 1e-7)
assertApproxEqual(compiledPlainJs.eval(scope), correctResult, 1e-7)

var total = 0
let total = 0

var suite = new Benchmark.Suite()
const suite = new Benchmark.Suite()
suite
.add(pad('(plain js) evaluate'), function () {
total += compiledPlainJs.eval(scope)
@@ -53,10 +53,10 @@ suite
total += math.parse(expr).compile().eval(scope)
})
.add(pad('(mathjs) parse, compile'), function () {
var node = math.parse(expr).compile()
const node = math.parse(expr).compile()
})
.add(pad('(mathjs) parse'), function () {
var node = math.parse(expr)
const node = math.parse(expr)
})

.on('cycle', function (event) {
@@ -74,7 +74,7 @@ suite
.run()

function assertApproxEqual (actual, expected, tolerance) {
var diff = Math.abs(expected - actual)
const diff = Math.abs(expected - actual)
if (diff > tolerance) assert.equal(actual, expected)
else assert.ok(diff <= tolerance, actual + ' === ' + expected)
}
@@ -9,16 +9,16 @@
* has room for improvements, it's not a fully fletched benchmark suite.
*/

var Benchmark = require('benchmark')
var padRight = require('pad-right')
var suite = new Benchmark.Suite()
const Benchmark = require('benchmark')
const padRight = require('pad-right')
const suite = new Benchmark.Suite()

function pad (text) {
return padRight(text, 40, ' ')
}

// fiedler matrix 25 x 25
var fiedler = [
const fiedler = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
[1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
[2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
@@ -48,8 +48,8 @@ var fiedler = [

// mathjs
(function () {
var math = require('../index')
var A = math.matrix(fiedler)
const math = require('../index')
const A = math.matrix(fiedler)

suite.add(pad('matrix operations mathjs A+A'), function () { return math.add(A, A) })
suite.add(pad('matrix operations mathjs A*A'), function () { return math.multiply(A, A) })
@@ -59,8 +59,8 @@ var fiedler = [

// sylvester
(function () {
var sylvester = require('sylvester')
var A = sylvester.Matrix.create(fiedler)
const sylvester = require('sylvester')
const A = sylvester.Matrix.create(fiedler)

suite.add(pad('matrix operations sylvester A+A'), function () { return A.add(A) })
suite.add(pad('matrix operations sylvester A*A'), function () { return A.multiply(A) })
@@ -70,8 +70,8 @@ var fiedler = [

// numericjs
(function () {
var numeric = require('numericjs')
var A = fiedler
const numeric = require('numericjs')
const A = fiedler

suite.add(pad('matrix operations numericjs A+A'), function () { return numeric.add(A, A) })
suite.add(pad('matrix operations numericjs A*A'), function () { return numeric.dot(A, A) })
@@ -81,27 +81,27 @@ var fiedler = [

// ndarray
(function () {
var ndarray = require('ndarray')
var gemm = require('ndarray-gemm')
var zeros = require('zeros')
var ops = require('ndarray-ops')
var pack = require('ndarray-pack')
var det = require('ndarray-determinant')
const ndarray = require('ndarray')
const gemm = require('ndarray-gemm')
const zeros = require('zeros')
const ops = require('ndarray-ops')
const pack = require('ndarray-pack')
const det = require('ndarray-determinant')

var A = pack(fiedler)
var B = zeros([25, 25])
const A = pack(fiedler)
const B = zeros([25, 25])

suite.add(pad('matrix operations ndarray A+A'), function () { return ops.add(B, A, A) })
suite.add(pad('matrix operations ndarray A*A'), function () { return gemm(B, A, A) })
suite.add(pad('matrix operations ndarray A\''), function () { return ops.assign(B, A); B.transpose(1, 0) })
suite.add(pad('matrix operations ndarray det(A)'), function () { return det(A) })
})()
})();

var durations = []
const durations = []

suite
.on('cycle', function (event) {
var benchmark = event.target
const benchmark = event.target
console.log(String(event.target))
durations.push(benchmark.name + ' avg duration per operation: ' + Math.round(benchmark.stats.mean * 1e6) + ' microseconds')
})
Oops, something went wrong.

0 comments on commit b3b9674

Please sign in to comment.