Skip to content

Instantly share code, notes, and snippets.

View jdgo-mars's full-sized avatar

João Martins jdgo-mars

  • 16:45 (UTC +03:00)
View GitHub Profile
function existsSum(arr, n, lIndex = 0, hIndex = null, iter = 0) {
const low = arr[lIndex];
const high = arr[hIndex || arr.length - 1];
const predicate = low + high;
if (iter === arr.length - 1) return false;
if (predicate === n) {
return true;
}
if (predicate < n) {
// increment lower index
// Wrap an async function so we catch any errors that might occur
const wrapAsync = handler => (req, res) =>
handler(req, res)
.then(result => res.json(result))
.catch(error => res.status(500).json({ error: error.message }))
const t = (function () {
var _listeners = {};
/**
* Compare with a new listener handler
* to make sure we are not adding the same handler
* @param String EventType
* @param Function Callback
* @returns Boolean true if exists false if not
*/
var _existsHandler = function (eventType, cb) {
function existsSum(arr, n, lIndex = 0, hIndex = null, iter = 0) {
const low = arr[lIndex];
const high = arr[hIndex || arr.length - 1];
const predicate = low + high;
if(iter === arr.length - 1 ) return false;
if(predicate === n) return true;
if(predicate < n) {
// increment lower index
return existsSum(arr, n, lIndex + 1, hIndex, iter + 1);
} else {
@jdgo-mars
jdgo-mars / useUserReducer.ts
Created April 15, 2019 18:18 — forked from schettino/useUserReducer.ts
Better Reducers with React and Typescript 3.4
import { useReducer } from 'react'
export function updateName(name: string) {
return <const>{
type: 'UPDATE_NAME',
name
}
}
export function addPoints(points: number) {
function BinarySearchTree(val) {
this.value = val;
this.left = null;
this.right = null;
}
BinarySearchTree.prototype.insert = function(value) {
let subtree = value < this.value ? 'left' : 'right';
if (this[subtree]) {
this[subtree].insert(value);
class LinkList {
constructor(value) {
this._head = { value, next: null };
this._tail = this._head;
}
insert(value) {
//update tail as needed
const node = { value, next: null };
this._tail.next = node;
<!DOCTYPE html>
<!--
*
* Copyright (C) 2016, bitmovin GmbH, All Rights Reserved
*
* This source code and its use and distribution, is subject to the terms
* and conditions of the applicable license agreement.
*
-->
<html lang="en">
@jdgo-mars
jdgo-mars / guessing_game.ex
Created November 29, 2019 19:40
Alchemist Camp
defmodule GuessingGame do
def guess(a, b) when a > b, do: guess(b, a)
def guess(low, high) do
answer = IO.gets("Maybe you thinking of #{mid(low, high)}? ")
case String.trim(answer) do
"bigger" ->
bigger(low, high)
var SBMonitor = []
var sysCallMap = {};
function getDiff(key) {
let diff = 0;
const now = new Date().getTime();
if(sysCallMap[key]) {
diff = now - sysCallMap[key];
}
sysCallMap[key] = now;