- jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
- Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
- AngularJS - Conventions based MVC framework for HTML5 apps.
- Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
- lawnchair - Key/value store adapter for indexdb, localStorage
This file contains hidden or 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 sumIntervals(intervals){ | |
var uniArr = [intervals[0]], helper = true; | |
intervals.reduce(function(lastInt, actualInt){ | |
uniArr.map(function(e){ | |
if (!helper) {return}; | |
//This validates if the array contains the klk[0] | |
if (actualInt[0] >= e[0] && actualInt[0] <= e[1]) { | |
if(e[1] < actualInt[1]) | |
e[1] = actualInt[1]; | |
helper = false; |
This file contains hidden or 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 removeZeros(array) { | |
// Sort "array" so that all elements with the value of zero are moved to the | |
// end of the array, while the other elements maintain order. | |
// [0, 1, 2, 0, 3] --> [1, 2, 3, 0, 0] | |
// Zero elements also maintain order in which they occurred. | |
// [0, "0", 1, 2, 3] --> [1, 2, 3, 0, "0"] | |
var length = array.length; | |
for(var i =0; length > 0; i++, length--){ | |
if(array[i] == 0){ | |
var temp = array[i]; |
This file contains hidden or 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 removeZeros(array){ | |
//Get initial zero index | |
var nextZero = getNextIndex(array,0); | |
var movedCounter = 0; | |
//If no zeros exists then we return the array | |
if (nextZero == -1) { return array}; | |
while(nextZero < (array.length - movedCounter)){ | |
//Copy the temporary zero, cause it could be a string or a number | |
var temp = array[nextZero]; | |
move(array, nextZero); |
This file contains hidden or 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 sum = function(number){ | |
return p(number, number); | |
} | |
var memo = []; | |
var p = function (n, m){ | |
if (m == 0 ) { return 0;}; | |
if (n == 0) { return 1}; | |
if (n < 0) { return 0}; | |
if (memo[n] == undefined) memo[n] = []; | |
var result = memo[n][m]; |
This file contains hidden or 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 Sudoku = function(data) | |
{ | |
// Private methods | |
// ------------------------- | |
var sudoku = data; | |
var sudokuLength = sudoku[0].length; | |
var uniqueAndValidNumber = function(array){ | |
var arr = array.slice().sort(), i; | |
for( i= arr.length; i--;) { | |
//The number shouldn't be repeated, has to be a number and couldn't be bigger than the length |
This file contains hidden or 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 formatDuration = function(duration){ | |
var result = '', | |
tempTime =0, | |
durations = [ | |
{ description : 'year', plural: "years", range : 31536000 }, | |
{ description : 'day', plural: "days", range : 86400 }, | |
{ description : 'hour', plural: "hours", range : 3600 }, | |
{ description : 'minute', plural: "minutes", range : 60 }, | |
{ description : 'second', plural: "seconds", range : 1 } | |
]; |
This file contains hidden or 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 allSquaredPairs = function(n){ | |
var max = Math.sqrt(n), | |
posibles = [], | |
temp =0, | |
result = [], | |
i =0; | |
for(; i<=max; i++) | |
{ | |
//Reference http://stackoverflow.com/questions/5380323/whats-the-fastest-algorithm-to-represent-a-prime-as-sum-of-two-squares | |
temp = Math.sqrt(n-i*i); |
This file contains hidden or 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 parseCSV(input, separator, quote) { | |
separator = separator || ','; | |
quote = quote || '"'; | |
var tempWord ='', c ='', temp = [], | |
closingPosition, result =[], specialCharacters = '$\\', | |
doubleQuoteRegex = new RegExp(quote+quote, 'g'); | |
if (specialCharacters.indexOf(quote) > -1) { | |
doubleQuoteRegex = new RegExp('\\' +quote+ '\\' +quote, 'g'); | |
}; |
This file contains hidden or 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 data = []; | |
var playlist = React.createClass({ | |
getInitialState: function(){ | |
return { lastSong: 0 } | |
}, | |
componentDidMount: function() { | |
setInterval(this.loadSongs, 5000); | |
}, | |
loadSongs: function() { |
OlderNewer