Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Issue converting if statements to switch case

I need to transpile a key is some situation. Right now i'm using this:

  transpileKey = key => {
    if (key === 'smsCode') key = 'code';
    if (key === 'phoneMobile') key = 'phoneNumber';
    if (key === 'passport') key = 'ssn';
    if (key === 'comment') key = 'notes';

    return key;
  };

And the function who calls it:

validate = (key) => {
    key = transpileKey(key)
    console.log(key)
}
validate('smsCode')

I wrote this switch to make it nicer, but it's not returning the proper value (I get the last one, 'notes' in the log).

  transpileKey = key => {
    switch (key) {
      case 'smsCode':
        key = 'code';
      case 'phoneMobile':
        key = 'phoneNumber';
      case 'passport':
        key = 'ssn';
      case 'comment':
        key = 'notes';
    }

    return key;
  };

What is wrong?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!