Skip to content

Instantly share code, notes, and snippets.

@1syo
Last active November 7, 2015 04:16
Show Gist options
  • Save 1syo/7c90842231ec6cb953ee to your computer and use it in GitHub Desktop.
Save 1syo/7c90842231ec6cb953ee to your computer and use it in GitHub Desktop.
tower-of-babel
var arg1 = process.argv[2];
var arg2 = process.argv[3];
import {PI, sqrt, square} from './Math';
console.log(PI);
console.log(sqrt(+arg1));
console.log(square(+arg2));
const PI = 3.141592;
var _sqrt = function(s, x, last){
return x != last ? _sqrt(s, (x + s / x) / 2.0, x) : x;
};
const sqrt = function(s){
return _sqrt(s, s/2.0, 0.0);
};
const square = function(x) {
return x * x;
};
export default {
PI,
sqrt,
square
};
var args = process.argv[2].split(",");
args = args.map((arg)=> +arg);
var sum = function(...args){
return args.reduce( (sum, n) => sum + n );
};
var avg = function(...values) {
return sum(...values) / values.length;
};
console.log(avg(...args));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment