Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
Is there any better way of coding this as it feels very impractical and takes a lot of space

Is there any better way of coding this as it feels very impractical and takes a lot of space. It is basically a random chance of getting a rarity, for example Getting a Uncommon sword.

if (Math.random() * 100 < 100 / (19.37 / NewData.PriceDivider)) {
        Rarity = Rarities.uncommon;
        Embed.addField("Rarity", Rarity, true);
        Embed.setColor("GREEN");
      } else if (Math.random() * 100 < 100 / (5.18 / NewData.PriceDivider)) {
        Rarity = Rarities.common;
        Embed.addField("Rarity", Rarity, true);
        Embed.setColor("GREY");
      } else if (Math.random() * 100 < 100) {
        Rarity = Rarities.basic;
        Embed.addField("Rarity", Rarity, true);
        Embed.setColor("GREY");
      }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Maybe you could avoid rewriting the assignment statements by using ternary operator :

let rdm = Math.random() * 100
const firstCase = 19.37 / NewData.PriceDivider
const secondCase = 19.37 / 100 / (5.18 / NewData.PriceDivider)

// Handle rdm === 100 here  if (rdm === 100) // do something

Rarity = rdm < firstCase ? Rarities.uncommon : rdm < secondCase ? Rarities.common : Rarities.basic
Embed.addField("Rarity", Rarity, true);
Embed.setColor(rdm < firstCase ? "GREEN" : "GREY");

If you want to handle the case where Math.random() === 1, I think you should handle it before this code block.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda