Last active
December 20, 2015 05:09
-
-
Save amscotti/6076549 to your computer and use it in GitHub Desktop.
Syntax comparison of Functions using CoffeeScript, Dart, and TypeScript.
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
divisible = 3 | |
divisibleReporter = (lastFound, nextDivisible) -> | |
"Found: #{lastFound}, Next: #{nextDivisible}" | |
divisibleKeeper = ((divisible) -> | |
lastFound = 0 | |
nextDivisible = divisible | |
(number) -> | |
if (number >= nextDivisible) | |
nextDivisible = (Math.floor(number/divisible) + 1) * divisible | |
lastFound = Math.floor(number/divisible) * divisible | |
console.log divisibleReporter(lastFound, nextDivisible) | |
)(divisible); | |
for n in [1..100] | |
divisibleKeeper(n) |
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
int divisible = 3; | |
String divisibleReporter(int lastFound, int nextDivisible) => "Found: ${lastFound}, Next: ${nextDivisible}"; | |
var divisibleKeeper = ((int divisible) { | |
int lastFound = 0; | |
int nextDivisible = divisible; | |
return (int number){ | |
if (number >= nextDivisible) { | |
nextDivisible = ((number/divisible).floor() + 1) * divisible; | |
lastFound = (number/divisible).floor() * divisible; | |
print(divisibleReporter(lastFound, nextDivisible)); | |
} | |
}; | |
})(divisible); | |
void main() { | |
for (var i = 0; i < 100; i++) { | |
divisibleKeeper(i); | |
} | |
} |
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 divisible = 3; | |
var divisibleReporter = function(lastFound:number, nextDivisible:number){ | |
return "Found: " + lastFound + ", Next: " + nextDivisible; | |
}; | |
var divisibleKeeper = (function(divisible:number) { | |
var lastFound = 0; | |
var nextDivisible = divisible; | |
return function(number:number) { | |
if (number >= nextDivisible) { | |
nextDivisible = (Math.floor(number / divisible) + 1) * divisible; | |
lastFound = Math.floor(number / divisible) * divisible; | |
console.log(divisibleReporter(lastFound, nextDivisible)); | |
} | |
}; | |
})(divisible); | |
for (var i = 1; i <= 100; ++i) { | |
divisibleKeeper(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should consider using the Coffeescript "do" keyword for your divisibleKeeper.