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
public class EjemplosRecursivosEIterativos { | |
// Calcular el factorial de un número de forma recursiva | |
// Recursivo significa que la función se llama a sí misma para resolver el problema | |
public static int factorialRecursivo(int n) { | |
if (n == 0) return 1; // Si n es 0, el resultado es 1 (como decir, 1 es el primer número para contar) | |
// Si no, multiplicamos n por el factorial del número anterior, hasta llegar a 1. | |
return n * factorialRecursivo(n - 1); | |
} |
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 {Injectable, Injector} from "@angular/core"; | |
import {HttpClient, HttpEvent, HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest} from "@angular/common/http"; | |
import {BehaviorSubject, Observable} from "rxjs"; | |
import {EnvironmentService} from "../environment.service"; | |
import {UserApplicationService} from "../services/user-application.service"; | |
import {filter, switchMap, take} from "rxjs/operators"; | |
import {AppStorageService} from "../services/app-storage.service"; | |
import {AccessAndRefreshToken} from "../shared/providers/authenticator-api/interfaces/authenticator-api-interfaces"; | |
@Injectable() |
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
fun main() = runBlocking{ | |
//With async this job take 3 seconds | |
val firstValue = async { validate1() } | |
val secondValue = async { validate2() } | |
println("${firstValue.await()} ${secondValue.await()}") | |
//Without this job take 6 seconds |
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
fun setTimeOut(handleFunction: () -> Unit, delay: Long): CountDownTimer { | |
val timer = object: CountDownTimer(delay, 1000){ | |
override fun onFinish() { | |
CoroutineScope(Dispatchers.Main).launch { | |
handleFunction() | |
cancel() | |
} | |
} |
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 formatPhoneNumber(phoneNumberString) { | |
var cleaned = ('' + phoneNumberString).replace(/\D/g, ''); | |
var match = cleaned.match(/^(\d{1}|\d{2}|\d{3}|)?(\d{3})(\d{3})(\d{4})$/); | |
if (match) { | |
var intlCode = (match[1] ? `+${match[1]} ` : ''); | |
return [intlCode, '(', match[2], ') ', match[3], '-', match[4]].join(''); | |
} |