Last active
November 7, 2015 04:16
-
-
Save 1syo/7c90842231ec6cb953ee to your computer and use it in GitHub Desktop.
tower-of-babel
This file contains 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 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)); |
This file contains 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
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 | |
}; |
This file contains 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 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