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

348
Views
Please help me to solve this problem about dates and function

Write a function normalize, that replaces '-' with '/' in a date string.

Example: normalize('20-05-2017') should return '20/05/2017'.

I have tried this:

let d = new Date('27-11-2021');

function normalize(session){    
     let normal = d.replace('-','/');
     
     return (session);
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

As you are being asked to pass a string representation of a date to the normalize function, you can use String.prototype.replaceAll() to replace each - with / in the string.

For this problem, there does not appear to be a need to parse the string as an actual javascript Date object.

// Write a function normalize, that replaces '-' with '/' in a date string.
// Example: normalize('20-05-2017') should return '20/05/2017'.
function normalize(stringDate) {
  const normal = stringDate.replaceAll('-', '/');
  return normal;
}

const result = normalize('20-05-2017')
console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

Try This or Use replaceAll instead of replace function because in new ES replaceAll is working.

let date = normalize('20-05-2017');
console.log('date: ',date);

function normalize(date){
    return (date.replace(/-/g,'/'));
}
about 4 years ago · Juan Pablo Isaza Report

0

First off, the date is invalid for some reason. In the constructor, you cannot pass in 27-8-2021. So for example, you can go this way.

let d = new Date();

d.toLocaleDateString() // returns '8/27/2021'
d.toLocaleDateString('en-in') // returns '27/8/2021'
about 4 years ago · Juan Pablo Isaza 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!