Skip to content

Instantly share code, notes, and snippets.

View germanescobar's full-sized avatar

German Escobar germanescobar

View GitHub Profile
type MachineContext = {
fromDate: Date;
toDate: Date;
glucose: GlucoseReading[];
};
type MachineEvent =
| {
type: 'SET_FROM_DATE';
fromDate: Date;
var Node = function(key, value, next, previous) {
this.key = key
this.value = value
this.next = next
this.previous = previous
}
/**
* @param {number} capacity
*/
var mostCommonWord = function(paragraph, banned) {
const words = paragraph.toLowerCase().split(/\W+/)
const freqs = frequencies(words, banned)
return findMaxWord(freqs)
};
function frequencies(words, banned) {
const freqs = {}
for (let w of words) {
if (w && !banned.includes(w)) {
var maxProduct = function(nums) {
let max = -Infinity
const memo = {}
for (let i=0; i < nums.length; i++) {
const result = dp(nums, i, nums.length, memo)
if (result.max > max) {
max = result.max
}
}
return max
var minimumDeviation = function(nums) {
nums.sort((a,b) => a - b)
let diff = nums[nums.length-1] - nums[0]
let diffExt = nums[0] !== nums[nums.length-1]
let canOperate = nums[0] % 2 !== 0 || nums[nums.length-1] % 2 === 0
while (diffExt && canOperate && diff > 1) {
console.log(nums, diff)
let oper = false
if (nums[0] % 2 !== 0) {
oper = true
var convert = function(s, numRows) {
if (numRows === 1) return s
const mat = buildMatrix(s, numRows)
return buildResult(mat)
};
function buildMatrix(s, numRows) {
const mat = initMatrix(numRows)
let r = 0, c = 0, down = true
var findAllConcatenatedWordsInADict = function(words) {
const result = []
for (let i=0; i < words.length; i++) {
if (findWord(i, words[i], words)) {
result.push(words[i])
}
}
return result
};
var averageOfLevels = function(root) {
const valuesByLevel = []
dfs(root, 0, valuesByLevel)
const result = []
for (let i=0; i < valuesByLevel.length; i++) {
const arr = valuesByLevel[i]
result.push(average(arr))
}
return result
var isPossible = function(nums) {
if (nums.length === 0) return true
if (nums.length < 3) return false
const clone = [...nums.slice(1)]
const seq = [nums[0]]
for (let i=0; i < nums.length && seq.length < 3; i++) {
const next = seq[seq.length - 1] + 1
if (nums[i] === next) {
clone.splice(i-seq.length, 1)
var findAndReplacePattern = function(words, pattern) {
const result = []
for (let i=0; i < words.length; i++) {
const word = words[i]
if (matchPattern(word, pattern)){
result.push(word)
}
}
return result
};