Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Created April 13, 2010 22:30
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 mbbx6spp/365187 to your computer and use it in GitHub Desktop.
Save mbbx6spp/365187 to your computer and use it in GitHub Desktop.
Simple math CoffeeScript example translated to Javascript.
# Creative Commons Attribution-Share Alike 3.0 United States License
# http://creativecommons.org/licenses/by-sa/3.0/us/
# By Susan Potter <http://geek.susanpotter.net>
(() ->
window: this
window.SimpleMath: {
square: (x) ->
x*x
cube: (x) ->
x*x*x
even: (x) ->
!(x%2)
odd: (x) ->
!!(x%2)
}
)()
SimpleMath.square(7) # => 49
SimpleMath.cube(7) # => 343
SimpleMath.even(7) # => false
SimpleMath.odd(7) # => true
// Creative Commons Attribution-Share Alike 3.0 United States License
// http://creativecommons.org/licenses/by-sa/3.0/us/
// Generated from CoffeeScript translator of previous CS code.
(function() {
var window;
window = this;
window.SimpleMath = {
square: function square(x) {
return x * x;
},
cube: function cube(x) {
return x * x * x;
},
even: function even(x) {
return !(x % 2);
},
odd: function odd(x) {
return !!(x % 2);
}
};
return window.SimpleMath;
})();
SimpleMath.square(7);
// => 49
SimpleMath.cube(7);
// => 343
SimpleMath.even(7);
// => false
SimpleMath.odd(7);
// => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment