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
function splitNumber(n, m_parts){ | |
var arr = []; | |
var eachPart = Math.ceil(n / m_parts); | |
for(var i = 0; i < m_parts; i++){ | |
arr.push(eachPart); | |
} | |
var diff = (eachPart * m_parts) - n; | |
for(var i = 0; i < diff; i++){ | |
arr[i%arr.length]--; | |
} |
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 swap = function(arr, i, j){ | |
var temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
return arr; | |
}; | |
var insertBefore = function(arr, i, j){ | |
if(i == j || i == j - 1) return arr; | |
else if(i < j) return insertBefore(swap(arr, i, i+1), i+1, j); | |
else if(i > j) return insertBefore(swap(arr, i, i-1), i-1, j); |
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
spectrum = getSpectrum(20, ['#2E7D32', '#ffee58', '#B71C1C']); | |
console.log(spectrum); | |
// [[46,125,50],[67,136,54],[88,148,58],[109,159,61],[130,170,65],[151,182,69],[171,193,73],[192,204,77],[213,215,80],[234,227,84],[255,238,88],[248,217,82],[241,196,76],[233,175,70],[226,154,64],[219,133,58],[212,112,52],[205,91,46],[197,70,40],[190,49,34]] | |
/* we can apply the color to css */ | |
$('div').css('background-color', 'rgb(' + spectrum[3] + ')'); |
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
function tempCSS(element, stylename, temp_value, fn){ | |
// Temporarily replace a css property and restore it after fn(); | |
var ret; | |
var original_value = element.css(stylename); | |
element.css(stylename, temp_value); | |
ret = fn(); | |
element.css(stylename, original_value); | |
return ret; | |
}; |
NewerOlder