Skip to content

Instantly share code, notes, and snippets.

View nramirez's full-sized avatar
lion mode!

Naz nramirez

lion mode!
View GitHub Profile
@nramirez
nramirez / gist:3802b889ecd99ff3e1db
Created January 22, 2015 18:36
Human readable duration format
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 }
];
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
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];
@nramirez
nramirez / gist:ccffcb0cf90e8f169eaf
Created January 19, 2015 20:43
removeZeros_without_specials
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);
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];
@nramirez
nramirez / gist:4e3ad8369dde3ede282b
Created January 18, 2015 20:26
Sum of Intervals
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;