Instantly share code, notes, and snippets.

# Guillermo Som elGuille-info

Created December 2, 2022 17:22
De un array numérico, encontrar el número que aparezca un número de veces impar (solo habrá un número que aparezca un número de veces impar)
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
 /* Given an array of integers, find the one that appears an odd number of times. There will always be only one integer that appears an odd number of times. Examples [7] should return 7, because it occurs 1 time (which is odd). [0] should return 0, because it occurs 1 time (which is odd). [1,1,2] should return 2, because it occurs 1 time (which is odd). [0,1,0,1,0] should return 0, because it occurs 3 times (which is odd).
Created December 1, 2022 07:32
Buscar el índice en el que la suma de un array es igual por ambos lados
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
 /* You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return -1. For example: Let's say you are given the array {1,2,3,4,3,2,1}: Your function will return the index 3, because at the 3rd position of the array, the sum of left side of the index ({1,2,3}) and the sum of the right side of the index ({3,2,1}) both equal 6.
Created November 30, 2022 18:42
Manipulación de arrays en JavaScript
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
 /* Del ejemplo de [Active learning: Printing those products]( https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Arrays?qs=arrays#active_learning_printing_those_products) */ //const list = document.querySelector('.output ul'); //const totalBox = document.querySelector('.output p'); let total = 0; //list.innerHTML = '';
Created November 30, 2022 13:19
Si una palabra tiene caracteres pares, devolver los 2 caracteres centrales, si tiene caracteres impares, devolver el carácter central
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
 /* You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd (impar), return the middle character. If the word's length is even (par), return the middle 2 characters. #Examples: Kata.getMiddle("test") should return "es"
Created November 30, 2022 11:45
Acumular letras de forma que la primera letra se muestre una vez, la segunda dos veces y así sucesivamente separándolas con un guion (JavaScript)
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
 /* Acumular letras, de forma que la primera letra se muestre una vez, la segunda 2 veces, etc. Debe empezar por una letra mayúscula y el resto minúsculas. Ejemplos: accum("abcd") -> "A-Bb-Ccc-Dddd" accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy" accum("cwAt") -> "C-Ww-Aaa-Tttt" */ function accum(s) {
Created November 30, 2022 11:02
Valida un pin numérico de solo 4 o 6 cifras con expresiones regulares (JavaScript)
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
 /* Explicación: ^ indica que no haya nada delante \d{4} un número de 4 cifras \d{6} un número de 6 cifras \$ indica que ya no haya más caracteres (el final de la línea) Cuando se hace en una sola expresión se ponen las dos comprobaciones entre paréntesis separados por |: /^(\d{6}|\d{4})\$/ */
Created November 29, 2022 20:02
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
 /* var str = "How can mirrors be real if our eyes aren't real"; if (str.toJadenCase(), "How Can Mirrors Be Real If Our Eyes Aren't Real") { // Es correcto. } else { // No es correcto. } */
Created November 27, 2022 12:43
Evaluar expresiones aritmáticas (27-nov-22)
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
 // Evaluar expresiones simples. // Se permite *, /, %, +, - con este nivel de precedencia. // Las expresiones entre paréntesis se evalúan primero. // // También se puede usar 'x' para multiplicar y ':' para dividir. // Se puede indicar '!', para calcular la factorial. //package com.example.evaluar; import java.io.BufferedReader;
Created November 16, 2022 18:23
Main para probar el evaluador de expresiones
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
 // EvaluarExpresiones. (16/nov/22 15.12) // Evaluador de expresiones simples a partir del contenido de una cadena. // Basado en el código de ejemplo de Prueba08 con sealed interface y records. //package com.example.evaluar; public class Main { public static void main(String[] args) throws Exception { System.out.println("Evaluar expresiones simples.");
Created November 16, 2022 18:23
Interface y records para evaluar expresiones
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
 // Expresiones // sealed interface y permits en records. // Los records son buenos candidatos para usarlos en permits porque son final. //package com.example.evaluar; sealed interface Expr //permits ConstantExpr, PlusExpr, TimesExpr, NegExpr, MinusExpr, DivideExpr { int eval();