Last active
August 8, 2020 23:37
-
-
Save wkoch/ebab99f10e7bba6a226e5a9c9dbeeb0f to your computer and use it in GitHub Desktop.
Revisions
-
wkoch renamed this gist
Aug 8, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
wkoch created this gist
Aug 8, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ console.log(10); console.log(5 + 3 + 4); console.log(9 - 1); console.log(6 / 2); console.log((2 * 4) + (4 - 6)); let a = 3; let b = a + 1; console.log(a + b + (a * b)) console.log(a == b) console.log(((a > b) && (b < (a * b))) ? b : a); if (a == 4) { console.log(6); } else if (b == 4) { console.log(6 + 7 + a); } else { console.log(25); } let maior = (a, b) => { return (a >= b ? a : b);} console.log(2 + (maior(a, 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ let square = (n) => {return n * n;} let sumOfSquares = (a, b, c) => { if ((a > b) && (b > c)) { return (square(a)) + (square(b)); } else if ((a > b) && (b < c)) { return (square(a)) + (square(c)); } else { return (square(b)) + (square(c)); } } console.log(sumOfSquares(2, 3, 4)); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ let average = (x, y) => { return ((x + y) / 2); } let improve = (guess, x) => { return average(guess, (x / guess)); } let square = (x) => { return x * x;} let good_enough = (guess, x) => { return (Math.abs(square(guess) - x) < 0.001); } let sqrt_iter = (guess, x) => { if (good_enough(guess, x)) { return guess; } else { return sqrt_iter(improve(guess, x), x); } } let sqrt = (x) => { return sqrt_iter(1.0, x);} // Examples console.log(sqrt(9)); console.log(sqrt(100 + 37)); console.log(sqrt(sqrt(2)) + sqrt(3)); console.log(square(sqrt(1000))); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ // Javascript implementation of the SICP exercises