This file contains 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 { useEffect, useState } from "react"; | |
export const useMercadoPago = (preferenceId, divEl) => { | |
const [status, setStatus] = useState(preferenceId ? "loading" : "idle"); | |
useEffect(() => { | |
const divContainer = document.getElementById(divEl); | |
let script = divContainer.querySelector("script"); | |
if (!preferenceId) { | |
setStatus("idle"); |
This file contains 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 debounce(func, duration) { | |
let timeout; | |
return function(...args) => { | |
const effect = () => { | |
timeout = null; | |
return func.apply(this, args); | |
} | |
clearTimeout(timeout); |
This file contains 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 throttle(func, delay) { | |
let shouldWait = false; | |
return function(...args) { | |
if (!shouldWait) { | |
func.apply(this, args); | |
shouldWait = true; | |
setTimeout(function() { | |
shouldWait = false; |
This file contains 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
// Binary search | |
// Take sorted array and search from the middle; | |
const values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
const binary = (val, arr) => { | |
let lower = arr[0]; | |
let upper = arr.length - 1; | |
// counter |
This file contains 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
// test cards | |
// https://developer.paypal.com/docs/classic/payflow/payflow-pro/payflow-pro-testing/#credit-card-numbers-for-testing | |
const card = 378282246310005; | |
let mod = 1; | |
let flag = true; | |
let sum = 0; | |
const digits = 16; | |