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 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 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
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
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 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; |
NewerOlder