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
/* | |
Solution to: | |
https://blog.svpino.com/2015/05/17/programming-challenge-merging-overlapping-intervals | |
*/ | |
function combineOverlappingIntervals(intervals){ | |
var overlapping = [], newOnes = []; | |
// Compare each interval with every other interval |
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
/* | |
Solution to | |
https://blog.svpino.com/2015/05/24/programming-challenge-the-position-of-the-element | |
*/ | |
function posOfEl(list,el){ | |
// if the element exist return the index | |
var index = list.indexOf(el); | |
if(index>=0){return index;} | |
// otherwise insert it in a copy |
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
/* | |
Towers of Hanoi | |
(non-recursive solution) | |
https://blog.svpino.com/2015/06/07/programming-challenge-towers-of-hanoi | |
*/ | |
function solveHanoi(discs){ | |
var towers = {a:[],b:[],c:[]}; |
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
Array.prototype.shuffle = function(){ | |
var x = this.slice(), y = []; | |
while(x.length){y.push(x.splice(Math.floor(Math.random()*x.length),1)[0]);} | |
return y; | |
} |
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 bit_test(num,bit){ | |
return ((num>>bit) % 2 != 0) | |
} | |
function bit_set(num,bit){ | |
return num | 1<<bit; | |
} | |
function bit_clear(num,bit){ | |
return num & ~(1<<bit); |
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
aardvark | |
aardwolf | |
aaron | |
aback | |
abacus | |
abaft | |
abalone | |
abandon | |
abandoned | |
abandonment |
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
// Example usage niceFormat | |
// new Date().niceFormat('yyyy-mm-dd hh:ii:ss') | |
// Example usage countdown | |
// new Date().countdown(dateInFuture,'ii:ss') | |
// try with new Date().countdown(new Date(new Date().getTime()+3600000),"ii:ss") | |
(function(){ | |
var a = { |
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
// options object example | |
/* | |
{ | |
decimals:2, | |
decimalSign:",", | |
thousandSep: " ", | |
currency:"SEK" | |
} | |
*/ |
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
$scope.changeWatch = function(){ | |
// An alternative to Angular $scope.$watch | |
// that does not trigger on initial load | |
var | |
init = true, | |
args = [].slice.call(arguments), | |
listener = args[1]; |
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
Number.prototype.slice = function(x,y){ | |
return (this+'').slice(x,y)/1; | |
} |