¡Te damos la bienvenida a este reto!

1

¡Bienvenido al mundo de JavaScript!

Día 1

2

Variables, funciones y sintaxis básica

3

Tipos de datos

4

Playground - Retorna el tipo

5

Tipos de datos - pt 2

Día 2

6

Operadores

7

Hoisting y coerción

8

Playground - Calcula la propina

9

Alcance de las variables

Día 3

10

Condicionales

11

Playground - Calcula años bisiestos

12

Switch

13

Playground - Obten información de mascotas según su tipo

14

Ciclos

15

Playground - Dibuja un triangulo

Día 4

16

Arrays

17

Playground - Encuentra al michi mas famoso

18

Objetos

19

Playground - Obten el promedio de los estudiantes

Día 5 - Checkpoint

20

Playground - encuentra el palindromo más grande

Día 6

21

Reasignación y redeclaración

22

Modo estricto

Día 7

23

Debugging y manejo de errores

24

Programación funcional

Quiz: Día 7

Día 8

25

Closures

26

Playground - Crea una calculadora con closures

27

Higher order functions

28

Playground - Crea tu propio método map

Día 9

29

ECMAScript

30

TC39

Quiz: Día 9

Día 10 - Checkpoint

31

ES6

32

ES7

33

Playground - Task planner

Día 11

34

Asincronismo

35

Playground - Promesas

36

Manejando el asincronismo

37

Playground - Resuelve el callback hell usando promesas

38

Playground - Resuelve el callback hell usando async/await

Día 12

39

Arrays a profundidad

40

Métodos de arrays: Every, Find y findIndex

41

Playground - Válida el formulario

Día 13

42

Métodos de arrays: Includes, Join y concat

43

Playground - agrupa los productos

44

Métodos de arrays: Flat y FlatMap

45

Playground - Encuentra la ubicación del valor buscado

Día 14

46

Mutable functions

47

Playground - Modifica una lista de compras

48

Métodos de arrays: sort

49

Playground - Ordena los productos

Día 15 - Checkpoint

50

Playground - Sistema de reservaciones de un hotel

Día 16

51

Programación orientada a objetos en JavaScript

52

Objetos literales

53

Playground - Congela el objeto recursivamente

Día 17

54

Prototipos en JavaScript

55

Playground - Modifica el prototype de los arrays

56

Playground - Crea un auto usando clases

Día 18

57

Abstracción en JavaScript

58

Playground - Sistema de carrito de compras

59

Encapsulamiento en JavaScript

60

Playground - Encapsula datos de los usuarios

Día 19

61

Herencia en JavaScript

62

Playground - Jerarquía de animales

63

Polimorfismo en JavaScript

64

Playground - Sistema de pagos

Día 20

Live Class

65

30 días de JS con Juan DC

66

30 días de JS con Nicobytes

No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Playground - Calcula años bisiestos

11/66

Aportes 128

Preguntas 5

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

🛡️🛡️🛡️Escudo anti spoilers🛡️🛡️🛡️
.
Me alegra que más estudiantes tomen está iniciativa para ayudar a la comunidad
.
La solución estará debajo del gif, pero antes de leerla te dejo un dato sacado de wikipedia acerca de los años bisiestos
.

Los años bisiestos se añaden para corregir el desfase que existe entre la duración del año trópico: 365 días 5 h 48 min 45,10 s (365,242189 días) y el año calendario de 365 días. Esto requiere que cada cuatro años se corrija el año calendario por una acumulación no contabilizada de aproximadamente 1/4 de día por año que equivale a un día extra.

.
Por lo que ahora sabes un poquito más que ayer

.

Explicación

Aquí tienes explicada la solución si es que no lograste completar este desafío.
.

function isLeapYear(year) {
  // Primero verificamos que el número sea positivo
  // Y además el número sea entero
  if(year % 1 != 0 || year <= 0){
    return false
  }

  // Verificamos que el año sea divisible entre 4
 // (la regla básica de los años bisiestos) 
  if(year % 4 === 0){
    // Si el numero es múltiplo de 100 y de 400 entonces es bisiesto
    if(year % 100 === 0 && year % 400 === 0){
      return true
    }

    // Si solo es multiplo de 100 no lo es
    if(year % 100 === 0){
      return false
    }
    // Si solo es múltiplo de 4, también lo es
    return true
  }

  // si no cumple con nada de lo anterior, no es bisiesto
  return false
}

Dale like a este comentario para poder disfrutando de esta experiencia 🔥

Hola les dejo un detalle por acá.
Las condiciones parecen contradictorias.

No es que deban cumplirse ambas.

Un año es bisiesto si cumple alguna de las siguientes condiciones:

Es divisible por 4, pero no por 100.

ó

Es divisible por 100 y por 400.

Solución sin if 😉

🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧

Me ayudo de Wikipedia 🤭

Existe un algoritmo que parte de tres proposiciones lógicas (supuestos):

p: Es divisible entre 4
q: Es divisible entre 100 ( ~ q significa no divisible entre 100)
r: Es divisible entre 400

La fórmula lógica para determinar si un año es bisiesto es la siguiente:

Lógica: p ^ q ( ~ q v r)

Traducido a código:

p && q ( !q || r)

Código

export function isLeapYear(year) {
  
 // Agrego el year > 0 para asegurar que sea positivo el año
  const p = (year % 4 == 0 && year > 0)
  const q = (year % 100 == 0 && year > 0)
  const r = (year % 400 == 0 && year > 0)

  return p && (!q || r)
}

¡Hola tú! Teniendo en cuenta que en los anteriores playground LeoCode dejó comentarios anti-spoiler, dejo uno aquí también con una imagen para evitar que te comas un spoiler del ejercicio, yo haré lo mismo en este ejercicio adelantándome un poco a LeoCode, así que… Ten tu imagen random, ¡Pero hey! también dejaré la solución al final, así que si no has hecho el ejercicio y no quieres ver la solución aún, no leas lo que hay después de la imagen

¿Y la solución pa’ cuándo?

Por su pollo, aquí la tienes, primero que todo, las condiciones que se dejan en la guía a pesar de ser exactas, siento que pueden ser un poco confusas… Quizás para ti no, o quizás opines lo mismo, así que recordar un problema similar un par de años atrás y recordé que me dijeron "Fácil, un año es bisiesto si es divisible por 4, así que, siguiendo esta lógica, deje un solo if en el que evalúa si es divisible en 4, usé el operador módulo (en el que obtiene el residuo de una división) y en caso que el residuo sea 0, es decir, que al dividir por 4 da un número entero, entonces es divisible por 4, llevando esta lógica a código, sería así:

export function isLeapYear(year) {
  if (year <= 0) return false;
  if (year % 4 === 0) {
    return true;
  }
  else {
    return false;
  }
}

Dejé dos if, debido a que en la guía dice Toma en cuenta que la función debe ser capaz de manejar valores no enteros o negativos. para que en caso que sea negativo, retorne un false de manera directa.

¿Quieres un reto? 😉

Este reto dependerá de ti, de tu motivación por aprender algo nuevo y de tu gusto por los retos, por más pequeños o grandes que sean, te reto a ti que lees esto, que hagas este ejercicio con el operador ternario ¿Primera vez que lo oyes? Muy útil y te recoomendaría que leyeras la documentación que dejé y soluciones este ejercicio con este operador, pero por favor, si vas a dejar alguna solución, deja una imagen al principio, di #NoALosSpoilersDeCodigo
¡Suerte en tu reto!

De verdad me siento tonto con los retos (no estoy entndiendo nada) mi esposa me dice que es porque hay cosas que implementan en los retos que aún no hemos visto en el reto. voy y reviso y dicen que los retos se hacen con lo que ya hemos visto (veo las soluciones de mis compañeros y van con más cosas de las que hemos visto.


.
.
.
.
.
.

export function isLeapYear(year) {
  // Tu código aquí 👈
  if ((((year % 4 == 0) && (year % 100 !== 0)) || ((year % 100 == 0) && (year % 400 == 0))) && (year >=0)) {
    return true;
  } else {
    return false;
  }
}

Jejeje segunda prueba Concluida, siempre se aprende algo nuevo o te das cuenta que estas usando mal un signo 😄.
.
.

.

.

.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  if (year % 4 === 0 && year%100 !==0 && year >0 || year % 100 === 0 && year % 400 === 0 && year>0) {
    return true;
  } else { return false; }

}

Esta es mi solución. sugiero tener mucho cuidado con el nivel en que corre cada if.

  export function isLeapYear(year) {
    //verifico que sea mayor que 0 y que su residuo al dividirlo entre 1 sea cero para estar seguro de que también es un entero
    if (year <= 0 && year % 1 != 0) {
      return false
    }
    // verifico que al dividirlo entre 4 su residuo sea de cero (divisible entre  4)
    if (year % 4 === 0) {
      //verifico que sea divisible entre 100 y 400
      if (year % 100 === 0 && year % 400 === 0) {
        return true
      }

      }
      //si solo es multiplo de 400 si lo es
    if (year % 400 === 0) {
        return true
    }

    //si solo es multiplo de 100 no lo es
    if (year % 100 === 0) {
        return false

    }
    // si no cumple con lo anterior entonces no lo es
    return false
}

Hola, dejo mi solucion

Caminito anti spoilers
🚗
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Llegamos 📍

export function isLeapYear(year) {
  if (year < 0 && !Number.isInteger(year)) return

  const isYearDividedBy4 = year % 4 === 0;
  const isYearDividedBy100 = year % 100 === 0;
  const isYearDividedBy400 = year % 400 === 0;
  return isYearDividedBy4 ? (isYearDividedBy100 && isYearDividedBy400) : false
}

quise probarlo con chat GPT-3 y este fue el resultado…
.
.
.
.
.
.
.

export function isLeapYear(year) {
  if (typeof year !== 'number' || year < 0 || !Number.isInteger(year)) {
    return false;
  }

  if (year % 4 === 0) {
    if (year % 100 === 0) {
      return year % 400 === 0;
    } else {
      return true;
    }
  } else {
    return false;
  }
}

export function isLeapYear(year) {
  // Tu código aquí 👈
    if (!(year%4) && year%100>0 || !(year%100) && !(year%400))
      return true
    else return false
}

Okay después de romperme el coco por 2 días, al fin conseguí, en parte debo decir que hice muchísima prueba y error incluido varios códigos de los demás colegas por aquí.
Pero trate de usar solo lo que ya se vio anteriomente hasta aquí.

function isLeapYear(year) {
  if (year > 0 && year % 1 == 0) {
    // Verifica si el año es positivo y es entero.
    // Si es positivo y entero, entonces se continua con la evaluación del año.
    if (year % 4 === 0) {
      // Si un año es divisible por 4, entonces es posible que sea bisiesto.
      if (year % 100 === 0) {
        // Si un año es divisible por 100, entonces no es bisiesto a menos que también sea divisible por 400.
        if (year % 400 === 0) {
          // Si un año es divisible por 400, entonces es bisiesto.
          return true
        } else {
          // Si un año es divisible por 100 pero no por 400, entonces no es bisiesto.
          return false
        }
      } else {
        // Si un año es divisible por 4 pero no por 100, entonces es bisiesto.
        return true
      }
    } else {
      // Si un año no es divisible por 4, entonces no puede ser bisiesto.
      return false
    }
  }
  // Si el año no es un número positivo y/o entero, entonces no puede ser bisiesto.
  return false
}

Mi solución

export function isLeapYear(year) {
  let esBisiesto = year % 4;
  let esDivisbleCien = year % 100;
  let esDivisbleCuatroc = year % 400;

  if (year % 1 != 0 || year <= 0) {
    return false;
  }

  if (esBisiesto == 0 && esDivisbleCien != 0) {
    return true;
  } else if (esDivisbleCien == 0 && esDivisbleCuatroc == 0) {
    return true;
  } else {
    return false;
  }
}

MI solución:

export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year < 0 || (Number(year) === year && year % 1 !== 0)) {
    return false;
  }
  else if(year%4==0 && year%100!=0){
    return true;
  } else if (year % 4 == 0 && year % 100 == 0 && year % 400 == 0){
    return true;
  } else {
    return false;
  }
}

Aportando en el day #3:

export function isLeapYear(year) {
  if (year > 0) {
    if ((year % 4) == 0 && (year % 100) != 0) {
      return true;
    } else if ((year % 100) == 0 && (year % 400) == 0) {
      return true;
    } else {
      return false;
    }
  } else {
    return false
  };
};

Reto completado 😃

export function isLeapYear(year) {
  //verificar que no sea negativo o decimal
  if (year >= 0) {
    // divsible por 4 pero no por 100, ademas evalua su es decimal o no.
    if (year % 4 === 0 && !(year % 100 === 0)) return true
    // si lo es por 100, que sea por 400 tambien
    if (year % 400 === 0) return true
  }
  return false
}

Mi solucion: 😄
function isLeapYear(year) {

if(year > 0){
if (!(year % 4) && !(year % 100) == false ) {
return true;

}else if (!(year % 400) && !(year % 100)) {
return true;
}
}

return false;
}

export function isLeapYear(year) {
  // Si el año no es un número o es negativo, devolvemos false
  if (typeof year !== "number" || year < 0) {
    return false;
  }

  // Comprobamos si el año es bisiesto según las condiciones
  if (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) {
    return true;
  } else {
    return false;
  }
}```

Costo pero salió, dejo mi respuesta.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

const isLeapYear = (year) => {

    if (Number.isInteger(year / 4) && !Number.isInteger(year / 100) && year >= 0) {
        return true
    } else if (Number.isInteger(year / 100) && Number.isInteger(year / 400) && year >= 0) {
        return true
    } else {
        return false
    }
}

My solution : shortcode …

export function isLeapYear(year) {
  if (year > 0 && Number.isInteger(year)) {
    const isLeap = [4, 100, 400].every((item) => year % item === 0)
    return (isLeap || (year % 4 === 0 && !(year % 100 === 0)));
  }
  return false;
}

Buenas Comparto mi solución. Saludos

export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year >= 0) { 
    if (year % 4 == 0 && year % 100 != 0)
      return true
    else if (year % 100 == 0 && year % 400 == 0)
      return true
    else return false  
  }else return false
}
function isLeapYear(year) {
  // Tu código aquí 👈
  if (year >= 1) {
    if ((year % 4 === 0 && year % 100 != 0) || (year % 4 === 0 && year % 400 === 0)) {
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}

Here is my solution ------------





function isLeapYear(year) {
  if (year % 4 === 0 && year % 100 > 0 || year % 100 === 0 && year % 400 === 0) {
    year = true;
  } else {
    year = false;
  }
  return year;
}

export function isLeapYear(year) {
if (year > 0 && Number.isInteger(year)) {
if (year % 4 === 0) {
return console.log(true);
}
} else {
return console.log(false);

}
}

Se que se ve muy verboso, pero estoy tratando de hacerlo con los conceptos básicos del lenguaje.

<code> 
export function isLeapYear(year) {
  // Tu código aquí 
  if (year > 0) {
    if ((year % 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0)) {
      return true
    }
    else {
      return false
    }
  }
  else {
    return false
  }
}

export function isLeapYear(year) {
  if (year % 1 != 0 || year <= 0) {
    return false;
  } else if ((year % 4 === 0) && (year % 100 !== 0)) {
    return true;
  } else if ((year % 100 === 0) && (year % 400 === 0)) {
    return true;
  } else {
    return false;
  }
}
export const isLeapYear = (year) => year > 0 ? (year % 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0) : false;

Para evitar cálculos con negativos, lo primero que se buscaría es que la variable year > 0. De ahi, solo habría que evaluar si satisface alguna de las condiciones dadas mediante operadores. A continuación dejo el código con el que solucioné el reto:

  if (year > 0 && year % 4 == 0 && year % 100 != 0 || year > 0 && year % 100 == 0 && year % 400 == 0){
    return true;
  }
  else {
    return false;
  }
export function isLeapYear(year) {
  let comprobar = year % 1;

  let residuo1 = year % 4;
  let residuo2 = year % 100;
  let residuo3 = year % 400;

  if ((year < 0) || (comprobar != 0) ) {
    return false
  }
  else {
    if ((residuo1 == 0 && residuo2 != 0) || (residuo2 == 0 && residuo3 == 0)) {
      return true;
    } else {
      return false;
    }
  }
}

Comparto mi solución al reto.





export function isLeapYear(year) {
  // Tu código aquí 👈
      let result;
    if((typeof(year) === "number" && year >= 0)){

      if ((((year % 4) === 0) && ((year % 100) !== 0)) || (((year % 100) === 0) && ((year % 400) ===0))){
            result = true;
        }else{
            result = false;
        }

    }else{
        result = false;
    }
    return result;    
}
export function isLeapYear(year) {
  // Tu código aquí 👈
  return year <= 0 ? false :
    (year % 4 === 0 && year % 100 !== 0) ? true :
      (year % 400 === 0 && year % 100 === 0) ? true : false
} 
export function isLeapYear(year) {

  if (year % 1 !== 0 || year <= 0) {
    return false;
  } else if (year % 4 === 0 && year % 100 !== 0) {
    return true;
  } else if (year % 100 === 0 && year % 400 === 0) {
    return true;
  } else {
    return false;
  }
}



export function isLeapYear(year) {
  if (year > 0) {
    if ((year % 4 === 0 && year % 100 != 0) || (year % 100 === 0 && year % 400 === 0)) {
      return true
    }
  }
  return false
}
  function isLeapYear(year) {
    if (year % 1 != 0 || year <= 0) {
        return false
    }

    if (year % 4 === 0 && year % 100 !== 0) {
        return true;
    } else if (year % 100 === 0 && year % 400 === 0) { 
        return true;
    } else {
        return false;
    }
}

Comparto mi solución, me parece que no es la más óptima, pero funciona 😃
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
if ( year % 4 == 0 && year % 100 != 0 && year > 0){
return true
} else if (year % 100 == 0 && year % 400 == 0 && year > 0) {
return true
} else {
return false
}
}

Mi solución:

.
.
.
.
.
.
.
.
.
.
👇

My solution guys!
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.export function isLeapYear(year) {
if (year > 0 && year % 4 == 0) {
return true
}
else {
return false
}
}

Comparto mi solución:
























export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year % 1 !== 0 || year <= 0) return false;

  if (year % 4 !== 0) return false;

  if (year % 100 === 0 && year % 400 === 0) return true;

  if (year % 100 === 0) return false;
}

¡¡NO ENTRES PUEDE ESTAR UNA SOLUCIÓN EN MENOS DE 9 LINEAS !!

Espero les ayude solo esta probado con estos casos
Return rompe el continuar con la ejecución de la función por lo que nos podemos ahorrar el else y con los caracteres de && ampersand permite usarlo como un AND en el cual se cumple todo o no entra además que nos ahorramos varios **if ** y se conserva la legibilidad.
En caso de no entrar pasa a return false y finaliza la ejecución.

export function isLeapYear(year) {
// Tu código aquí 👈
if (year%4== 0 && year%100== 0 && year%400==0) {
return true;
}
return false;
}

Compartiendo mi solucion

Me pareció raro que lo haya resuelto porque no tuve que corregir nada y me salió a la primera 🔥:

function isLeapYear(year) {
  if (year % 1 != 0 || year <= 0) { 
    return false
  } else if (year % 4 == 0 && (year % 100 != 0)) {
    return true;    
  } else if (year % 100 == 0 && year % 400 == 0) {
    return true
  } else {
    return false;
  }
}

les dejo mi solución:

function isLeapYear(year) {
    if (year % 4 === 0 && year % 100 >= 0) {
      console.log("true");
    } else if (year % 100 === 0 && year % 400 === 0) {
      console.log("true");
    } else {
      console.log("false");
    }
  }

 isLeapYear(2024);

Investigue un poco el calculo del año bisiesto ya que no entendí muy bien como se pusieron aquí
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  let firstCondition = year % 4
  let secondCondition = year % 400
  if (year > 0 && typeof (year) === 'number') {
    if (firstCondition === 0 &&  year % 100 !== 0 ){
      return true
    } else if (secondCondition === 0) {
      return true
    } else {
      return false
    }
  } else {
    return false
  }
}

Acá les va mi solución uwu

export function isLeapYear(year) {
  // Tu código aquí 👈
  return ((year % 4 === 0 && year % 100 != 0) || (year % 100 === 0 && year % 400 === 0)) && (year >= 0 ) 
}

Creo que me enrede más de la cuenta pero aquí está mi resultado
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  if ((year >= 0) && (year % 4 === 0 && year % 100 !== 0) || (year % 100 === 0 && year % 400 === 0)) {
    return year = true;
  } else {
    return year = false;
  }
}

🛡️🛡️🛡️Escudo anti spoilers🛡️🛡️🛡️

export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year % 100 && year % 400) {
    return false
  } else if (year % 4) {
    if (year % 100) {
      return true
    } else {
      return false
    }
  }
  else {
    return true
  }
}

Solución… 😄

export function isLeapYear(year) {
  if (year % 4 == 0 && year >= 0) {
    if (year % 100 != 0){ 
      return true;
    }else { 
      if (year % 400 == 0) {
        return true;
      } else {
        return false;
      }
    }
  } else { 
    return false;
  }
}

.
.
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  if (((year % 4 == 0) && !(year % 100 == 0))
    || ((year % 100 == 0) && (year % 400 == 0))) {
    return true
  } else {
    return false
  }
}

isLeapYear(2000)

Saludos, adjunto mi solución.

export function isLeapYear(year) {
  if(year < 0) return false
  if (isDivisible(year, 4) && !isDivisible(year, 100)
  || isDivisible(year, 100) && isDivisible(year, 400)) {
    return true
  }
  else {
    return false
  }
}

function isDivisible(dividend, divisor) {
  return !Boolean(dividend % divisor)
}

Hola dejo mi solución

export function isLeapYear(year) {
  if ((year < 0) && (year % 1 != year)) {
    return false
  }
  if ((year % 4 == 0) && (year % 100 != 0)) {
    return true
  } else if ((year % 100 == 0) && (year % 400 == 0)) {
    return true
  } else  return false 
}

Bueno aqui esta mi solucion pero no quiero que sea un spoiler, así que los invito a que lo intenten ustedes mismos
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year > 0 && (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0)) {
      return true;
  }
  return false;
}

El código funciono ¯_(ツ)_/¯

export function isLeapYear(year) {
  if (typeof year === "number" && year % 100 && year % 400) {
    return false
  } else if (typeof year === "number" && year % 4) {
    return false
  } else {
    return true
  }
}

Solución Dia #3

export function isLeapYear(year) {
  // Día 3 💚
  if (year > 0 && year % 4 === 0 && year % 100 !== 0
    || year % 100 === 0 && year % 400 === 0 
      ){
    return true;
  }
  return false;
}

mi respuesta

export function isLeapYear(year) {
  // Tu código aquí 👈
  return (year > 0 && year % 4 === 0) ? true : false;
  
}

Aquí dejo mi solución, háganme saber si esta del todo correcta por favor!
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

<code> 
export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year <= 0 || Number.isInteger(year) === false) {
    return false;
  } else if (year % 4 === 0 && year % 100 != 0) {
    return true;
  } else if (year % 100 === 0 && year % 400 === 0) {
    return true;
  } else return false;
}

Esta es mi propuesta de solución

export function isLeapYear(year) {
  	return (year % 4 == 0 && year > 0) && 
		!(year % 100 == 0 && year > 0) || 
		year % 400 == 0 && year > 0 
		? true : false;
}

export function isLeapYear(year) {
  return (year > 0 && (year % 4 == 0 && year % 100 !=0) || (year % 100 == 0 && year % 400 == 0)) ? true : false 
}

Por fin logre mi codigo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

export function isLeapYear(year) {
if (Number.isInteger(year) && year >= 0) {
if (year % 4 === 0 && !(year % 100 !== 0)) {
if (year % 100 === 0 && year % 400 === 0) {
return true
} else {
return false
}
} else {
return false
}
} else {
return false
}
}

Hola a todos, yo hice mi solución en un solo if
⚠️⚠️ANTI-SPOILER⚠️⚠️
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  if (year >= 0 && year % 4 === 0 && year % 100 !== 0 || year >= 0 && year % 400 === 0 && year % 100 === 0) {
    return true
  } else {
    return false
  }
}

Mi solución:
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  // Tu código aquí 👈
  if ((year % 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0)) {
    return true;
  }
  return false
}

Mi solución, cualquier recomendación de mejora es bien recibida 😁

export function isLeapYear(year) {
  if (year <= 0) {
    return false
  } else if (((year % 4 === 0) && (year % 100 !== 0)) || ((year % 100 === 0) && (year % 400 === 0))) {
    return true
  } else {
    return false
  }
}

🚩🚩🚩
SPOILER
🚩🚩🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩
🚩

export function isLeapYear(year) {
  return year <= 0 ? false :
          (year % 4 === 0 && year % 100 !== 0) ? true :
            (year % 400 === 0 && year % 100 === 0) ? true :
              false
}

¡Hola, Platzinauta!
Objetivo
En este desafío, debes crear la lógica de la función isLeapYear, que determina si un año es bisiesto o no
Mi solución,
Se detalla hasta abajo.⬇


































export function isLeapYear(year) {
  //@autor:dmos
  let rta = false;
  if (year > 0)
    rta=(year % 4 == 0 && year % 100 != 0) ||(year % 100 == 0 && year % 400 == 0);
  return rta;
}

export function isLeapYear(year) {
// Tu código aquí 👈
if (year <= 0) {
return false;
}
if (year % 4 == 0 && year % 100 != 0) {
return true;
} else if (year % 100 == 0 && year % 400 == 0) {
return true;
}
return false;
}

Dejo otra solución con if:

// Validamos si no es entero y negativo
    if ( !Number.isInteger(year) || !(year > 0) ){
        return false;
    }
    //Validamos la condición de año bisiesto
    if ((year % 4 == 0) && (year % 100 != 0) ) {
      return true;
    } else if ((year % 100 == 0) && (year % 400 == 0) ) {
      return true;
    }
    else {
      return false;
    } 

mi solucion:

  if (((year % 4) == 0) && (year > 0)) {
    return true
  } else
  { return false }  

les comparto mi solución.

export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year >= 0) {
    if ((year % 4 == 0) && (year % 100 != 0)) {
      return true
    } else if ((year % 100 == 0) && (year % 400 == 0)) {
      return true
    } else {
      return false
    }
  } else {
    return false
  }
}

Aquí te dejo una posible solución para el desafío:

<export function isLeapYear(year) {
  // Si el año no es un número entero positivo, retorna false
  if (!Number.isInteger(year) || year < 0) {
    return false;
  }

  // Si el año es divisible por 4 pero no por 100, o es divisible por 400, retorna true
  if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
    return true;
  }

  // En cualquier otro caso, retorna false
  return false;
}> 

Explicación:

Primero, se verifica si el año es un número entero positivo. Si no lo es, se retorna false de inmediato.
Luego, se verifica si el año cumple con las condiciones para ser bisiesto, y se retorna true en caso afirmativo. Si no cumple con las condiciones, se retorna false.
Ten en cuenta que hay otras formas de implementar esta función, pero esta es una de las más sencillas y directas.

export function isLeapYear(year) {
// Tu código aquí 👈
if (year % 1 != 0 || year <= 0) {
return false
}
if (year % 4 === 0 && year % 100 !== 0) {
return true;
} else if (year % 400 === 0 && year % 100 === 0) {
return true;
} else {
return false;
}
}

Es bueno no tener spoilers pero si me gustaria compartir mi codigo por si necesitan alguna guia

export function isLeapYear(year) {
  if (year >= 0) {
    return (year % 400 === 0) ? true :
      (year % 100 === 0) ? false :
        year % 4 === 0 
  }
  return false
}

Comparto mi código, valida también números enteros.

export function isLeapYear(year) {
  if (year >= 0) {
    if (year % 4 == 0 && year % 100 != 0) {
      return true
    }
    else if (year % 100 == 0 && year % 400 == 0) {
      return true
    }
    else {
      return false
    }
  } else {
    return false
  }
}

Hola. Comparto mi solución:

export const isLeapYear = (y) => y > 0 && (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)

Es una arrow function expression con el parámetro renombrado como ‘y’. Devuelve el resultado lógico de evaluar si el año es positivo, y además si cumple la condición 1 (div por 4 pero no por 100) o la condición 2 (div por 400)

Comparto mi solucion al final, No Spolilers…
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

Aquí muestro mil código:

export function isLeapYear(year) {
var bisiesto = false;
var div4 = year % 4;
var div100 = year % 100;
var div400 = year % 400;
if (year > 0) {
if (div4 === 0 && div100 !== 0) {
bisiesto = true;
} else if (div100 === 0 && div400 == 0) {
bisiesto = true;
}
}
return bisiesto
}

Por primera vez quiero comentar, y es que es primera vez que me siento un poco al dia con la clase o evento que esta pasando. Agradezco cualquier observacion 😃

function isLeapYear(year) {

  if (year / 4 > 0 && year % 4 === 0) {
    return true
  }

  else if (year % 100 === 0 && year && 400 === 0){
    return true
  }
  else {
    return false
  }

}
export function isLeapYear(year) {
  // Tu código aquí 👈
    if (year % 4 == 0 && year > 0) {
      if (year % 100 == 0) {
        return true
      } else {
        return true
      }
    } else {
      return false
    } 
  
}

Mi solucion la hice pensando en la segunda condicion ya que con la primera (Es divisible por 4, pero no por 100.) no lograba sacarla :

export function isLeapYear(year) {
  if ((year % 100 == 0) && (year % 400 == 0)) {
    return true
  } else {
    return false
  }
}

Mi aporte 😎🤯

export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year % 1 === 0 && year > 0) { 
    if (year % 4 === 0 && year % 100 !== 0) {
      return true
    } else if (year % 100 === 0 && year % 400 === 0) {
      return true
    }
  }
  return false
}

Si es divisible por 400 es bisiesto, por lo tanto con es verificación bastó en mi caso

export function isLeapYear(year) {
  if (year % 400 === 0) {
    return true
  } else {
    return false
  }
}

🛡️🛡️🛡️ Sin spoilers 🛡️🛡️🛡️

Mi solución 👇

export function isLeapYear(year) {
  if (year <= 0 && typeof year === 'number') return false;

  if (year % 4 !== 0) return false

  if (year % 100 === 0 && year % 400 === 0) return true;

  if (year % 100 === 0) return false

  return true;
}

Aca dejo mi solución, usando…

Else If y Math.sign

function isLeapYear(year) {
  // Tu código aquí 👈
  if (year % 4 === 0 && year % 100 !== 0 && Math.sign(year) !== -1) {
    return true;
  } else if (year % 100 === 0 && year % 400 === 0 && Math.sign(year) !== -1) {
    return true;
  } else {
    return false;
  }
}

Aqui dejo mi funcion con else if, dejo espacio para no spoilear

function isLeapYear(year) {
  if (year <= 0) {
    return false
  }

  else if (year % 1 != 0) {
    return false
  }

  else if (year % 4 === 0 || year % 100 != 0) {
    return true
  }

  else if (year % 100 === 0 && year % 400 === 0) {
    return true
  }

  else {
    return false
  }
}

Aquí les dejo una solución corta, pero no se que tan efectiva sea😅.

export function isLeapYear(year) {
  return (year % 100 && year % 400) || (year % 4 && !(year % 100)) ? false : true; 
} 

Sin spoilers
*
*
*
*
*
*
*
*
*

export function isLeapYear(year) {
  if (year % 4 === 0 && year % 100 === 0 && year % 400 === 0) {
    return true;
  } else { return false;}
}

Puede resolverse fácilmente sin ifs de la siguiente manera

-ANTI SPOILER-

-ANTI SPOILER-

-ANTI SPOILER-

export function isLeapYear(year) {
  return (year>=0 &&((year%4===0 && year%100!==0) || (year%400===0)))
}

Puede dividirse en varias partes

  1. El año debe ser mayor o igual a 0. 0. year>=0
  2. Operador AND (&&)
  3. Se compara si el año es divisible por 4 year%4===0 y si el año NO es divisible por 100 year%100!==0
  4. Operador OR (||), que conecta el punto 3 con el punto 5
  5. Se compara si el año es divisible por 400. (year%400===0) (No es necesario comparar si es divisible por 100, ya que cualquier año divisible por 400 es divisible por 100)

Si NO se cumple el punto 1, toda la sentencia retorna false
Si se cumple el punto 1, se evaluarán las sentencias del punto 3 y las del punto 5. Si cualquiera de esas dos da verdadero, entonces es un año bisciesto, por tanto, devuelve true

Aquí dejo mi solución usando operadores ternarios

export function isLeapYear(year) {
  // Tu código aquí 👈
  if (year % 1 != 0 || year <= 0) {
    return false;
  }

  return (year % 4 == 0 && year % 100 != 0) ? true
    : (year % 100 == 0 && year % 400 == 0) ? true
    : false;
}

Mi solucion al reto :

Cuando aprendí programación me enseñaron un principio que me ha servido mucho… Divide y venceras
Spoiler alert!!!
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Mi solución:
export function isLeapYear(year) {
// Tu código aquí 👈
let div4 = (year % 4) == 0 ? true : false;
let div100 = (year % 100) == 0 ? true : false;
let div400 = (year % 400) == 0 ? true : false;
if (year <= 0 || !Number.isInteger(year)) return false;
if ((div4 && !div100) || (div100 && div400)) return true
else return false
}

. SPOILERSSSSSSSSSSS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  return year % 1 === 0 && year > 0 ? year % 4 === 0 : false
}

Mi solución 😄

function isLeapYear(year) {
    let resultado 
    if (year <= 0 || !Number.isInteger(year)) {
      resultado = false
    }else if ((year % 4 === 0 && year % 100 !== 0) || (year % 100 === 0 && year % 400 === 0)) {
      resultado = true
    } 
    return resultado
  }
export function isLeapYear(year) {
  if (true) {
    if (year % 4 == 0 && year > 0) {
      return true
  }
    else if (year % 100 == 0 && year > 0) {
      return true
    }
    else if (year % 400 == 0 && year > 0) {
      return true
    }
    else {
      return false
    }
  }
}

Me gusta ver que muchos tienen una respuesta diferente a la mía, aquí esta mi respuesta.
Hola, dejo mi solución
anti spoilers
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  if (year < 0)
  {
    return false;
  }
  if (year % 4 === 0 && year % 100 !== 0)
  {
    return true;
  }
  if (year % 400 === 0 && year % 100 === 0)
  {
    return true;
  }
  return false;
}

dejo mi solución.

utilice varias comprobaciones adicionales para manejar casos de entrada no válidos. Comprueba si el valor de entrada no es un número válido, si es un número no finito, si no es un número entero o si es un número negativo.

Si se cumple cualquiera de estas condiciones, devolvemos false porque el año no es válido.

.
.
.
.
.
.
.
.
.
.
.
.

export function isLeapYear(year) {
  if (isNaN(year) || typeof year !== 'number' || !Number.isFinite(year) || year % 1 !== 0 || year < 0) {
    return false; // no es un año válido
  }

  if (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) {
    return true; // es un año bisiesto
  } else {
    return false; // no es un año bisiesto
  }
}

Hola, esta es mi solución, saludos!

export function isLeapYear(year) { 
  if (year%4===0 && year%100===0 && year%400===0) {
    return true;
  } else { 
    return false;
  }
}

Esta es mi propuesta.
Mi pasó algo curioso.
Al usar el operador === ! funcionó con los ejemplos dados. Pero al intentar usar !== me marcó error.

export function isLeapYear(year) {
  //Definiendo variable para guardar resultado
  let resultado = undefined

  //Estableciendo condiciones
  if (year % 4 === 0 && year % 100 ===! 0) {
    resultado = true
  }
  else if (year % 100 === 0 && year % 400 === 0) {
    resultado = true
  }
  else resultado = false

  return resultado
}

isLeapYear(2000)
isLeapYear(-2024)
isLeapYear(1984.25)

the solution

export function isLeapYear(year) {
  if (year<0) {
    return false;
  }
  else if (year % 4 == 0 && year % 100 != 0) {
    return true;
  } else if (year % 100 ==0 && year % 400 == 0) {
    return true;
  } else {
    return false;
  }
}

Esta es mi solución.

Cuidado con los spoilers

export function isLeapYear(year) {
  let output = false;
  //valido que el input sea positivo y múltiplo de 4
  if (year >= 0 && year % 4 === 0) {
    output = true;
    //valido que el numero no sea divisible sobre 100
    if (year % 100 === 0) {
      output = false;
    }
    //pero si por 400
    if ( year % 400 === 0) {
      output = true;
    }
  }

  return output;
}

undefined