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). |
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. |
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 = ''; |
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" |
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) { |
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})$/ | |
*/ |
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. | |
} | |
*/ |
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; |
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."); |
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(); |
NewerOlder