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
from collections import deque | |
def compare(a, b): | |
return -1 | |
def sort_horizontal_axis(matrix): | |
result = sorted(matrix, lambda a,b : -1) | |
return result | |
def sort_horizontal_axis_lambda(matrix): |
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
import math | |
def fib(n): | |
return int(round(pow(((1 + math.sqrt(5)) / 2), n) / math.sqrt(5))) | |
# complexity O(n) | |
# space O(n) |
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 checkIfIsPowerOfTwoOrReturnPrevious(number) { | |
var previousNumber = number | |
number = number | (number >> 1); | |
number = number | (number >> 2); | |
number = number | (number >> 4); | |
number = number | (number >> 8); | |
number = number | (number >> 16); | |
var result = number - (number >> 1); | |
if (result === previousNumber) { | |
result = true |
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
/* | |
pure functions are those that: | |
- are syncronous | |
- same input returns same output | |
- do not have collateral damage (change values from different scopes) | |
*/ | |
//Examples of pure functions | |
function (a, b) { |
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 location1 = new google.maps.LatLng(34.04429454929703, -118.22793351693724); | |
var location2 = new google.maps.LatLng(33.688522885631706, -116.15151750131224); | |
var location3 = new google.maps.LatLng(32.69561555501597, -117.06338273568724); | |
var location4 = new google.maps.LatLng(34.525395303965354, -117.27212297006224); | |
var map; | |
var mapOptions = { center: new google.maps.LatLng(42.5584308, -70.8597732), zoom: 3, | |
mapTypeId: google.maps.MapTypeId.ROADMAP }; |
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
//exec with node.js | |
this.me = 'context file:'; | |
var names = ["José", "Alfredo", "Ernesto"]; | |
var person = { | |
me: 'context person:', | |
greet: function () { | |
names.forEach(function (name) { | |
console.log(this.me, 'saying hello to', name); // this print: undefined saying hello to ${name} | |
}); |
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 isCommonFactorOf(arrayOfNumbers, factor) { | |
var numbers = arrayOfNumbers; | |
var length = numbers.length; | |
var minor = 0; | |
for (let i=0; i < length; i++) { | |
let number = numbers[i]; | |
if (i===0 || number < minor) { | |
minor = number; | |
if (factor > minor) { |
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 getCommonFactorsOf(arrayOfNumbers) { | |
var numbers = arrayOfNumbers; | |
var length = numbers.length; | |
var minor = 0; | |
for (let i=0; i < length; i++) { | |
let number = numbers[i]; | |
if (i===0 || number < minor) { | |
minor = number; | |
} |
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 getFactorsOf(number) { | |
var factors = []; | |
var factor = 1; | |
var stopped = false; | |
while (stopped != true) { | |
if (number % factor === 0) { | |
let a = number / factor; | |
let b = factor; |