Skip to content

Instantly share code, notes, and snippets.

@amscotti
Last active December 20, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amscotti/6076549 to your computer and use it in GitHub Desktop.
Save amscotti/6076549 to your computer and use it in GitHub Desktop.
Syntax comparison of Functions using CoffeeScript, Dart, and TypeScript.
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)
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);
}
}
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);
}
@mrbrdo
Copy link

mrbrdo commented Nov 23, 2013

You should consider using the Coffeescript "do" keyword for your divisibleKeeper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment