Skip to content

Instantly share code, notes, and snippets.

View jefsnare's full-sized avatar

Jeffrey de Graaf jefsnare

View GitHub Profile
@jefsnare
jefsnare / pattern.js
Created October 30, 2013 12:57
JS pattern
// top-level namespace
var myApp = myApp || {};
// directly assign a nested namespace
myApp.library = {
foo:function(){
//...
}
};
let roundUpValueByStep = (value, step) => {
return Math.ceil(value * (1 / step)) / (1 / step);
}
console.log(roundUpValueByStep(1.25, 0.5)); // 1.5
console.log(roundUpValueByStep(1.77, 0.5)); // 2
console.log(roundUpValueByStep(1, 0.5)); // 1
console.log(roundUpValueByStep(2.1, 0.25)); // 2.25
console.log(roundUpValueByStep(2.45, 0.25)); // 2.5
//DO NOT USE FRAMEWORKS
/**
* 1. Below discount rule should have dynamic data
* - Create a function to fill this dynamic data
* - Append to a HTML element with class .container
*/
var discountRule = 'Add two more 2 products and receive 5 euro discount!';