Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
Suppose a class object has related properties, is there a better way to initialize than hard-code the relationship?

I have a Budget class with an annual, monthly, and weekly property. Is there a better way to do it than below?:

class Budget{
    //based on choice, the initializer assigns, then calculates the two other properties
    constructor(value, choice) {
        this.value = value;
        this.choice = choice;
        this.annual = 0;
        this.monthly = 0;
        this.biweekly = 0;
    }

    initialize() {
        this.choice == 1 ? (this.annual = this.value,
                            this.monthly = this.annual/12,
                            this.biweekly = this.annual/52) :
        this.choice == 2 ? (this.monthly = this.value,
                            this.annual = this.monthly*12,
                            this.biweekly = this.annual/52):
        (this.biweekly = this.value,
         this.annual = this.biweekly*52,
         this.monthly = this.annual/12);
                            
    }


}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda