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

203
Views
How to change "/" in the first word with function if it has 3 words and 2 words are invalid

I have 3 variables

let oneWord = "offering" 
let twoWord = "test_offering"  
let threeWord = "loan_offering_data"

I want to make where if the value of TwoWord is executed/displayed as test-offering and suppose the value of threeWord is executed/displayed it becomes loan/offering-data

how to make a function to meet the above criteria dynamic?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

function reformat(word) {
    const wds=word.split("_");
    if (wds.length ===1) return word;
    if (wds.length ===2) return wds.join("-");
    if (wds.length ===3) return `${wds[0]}/${wds[1]}-${wds[2]}`;
    throw new Error("too many words");
}
about 4 years ago · Santiago Gelvez Report
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!