Light Mode
Dark Mode
What's wrong with my code?

Hi, this is my code, what is wrong? when I run code pass without a problem, but when I check solution is the problem

function convertDate(date: string): string {
    let arr = date.split('/').reverse().join('-')
    if( new Date(arr) == 'Invalid Date'  ){return "Error: Invalid date."}

    return arr
}

this is the console out: 5,9: This comparison appears to be unintentional because the types 'Date' and 'string' have no overlap.

assert.strictEqual(convertDate("25/12/2021"), "2021-12-25");

Thanks!

Created: Dec. 29, 2023, 5:29 p.m.
Updated: Jan. 2, 2024, 1:32 p.m.
0
13
User avatar
maxitenia