Skip to content

Instantly share code, notes, and snippets.

@CharlotteGore
Created June 13, 2014 08:22
Show Gist options
  • Save CharlotteGore/8063f37be592d4951e57 to your computer and use it in GitHub Desktop.
Save CharlotteGore/8063f37be592d4951e57 to your computer and use it in GitHub Desktop.
// version one... Create a clamp method.
Math.prototype.clamp = function clamp (num, min, max){
return Math.min(min, Math.max(num, max));
}
function getDayOfWeek (day){
return Math.clamp(day / 7, 0, 51)
}
// version two, module style
// clamp.js
module.exports = function clamp (num, min, max){
return Math.min(min, Math.max(num, max))
}
// days.js
var clamp = require('./clamp.js')
function getDayOfWeek (day) {
return clamp(day / 7, 0, 51)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment