Hello!
Today's question is this!
The 2nd of February 2020 is a palindromic date in both dd/mm/yyyy and mm/dd/yyyy format (02/02/2020). Given a
date
in dd/mm/yyyy format, returnTrue
if the date is palindromicin both date formats, otherwise returnFalse
.
From : Palindromic Dates // Edabit
The code is this!
So, first, let's see the no_slash variable.
This variable replaces slash(/) to an empty string.
Then, I made a variable reversed string and make a for loop.
In the for loop, we will reverse the date and appending to reversed string.
And then, look at it if the reversed string is same with no slash.
Then, this is the British date but the American date is mm/dd/yyyy format.
I splited the date when the / is not gone.
And we will rearrenge date(which means make it to mm/dd/yyyy format.)
Lastly, we will see if the rearrenged date is same with the reversed string.
Easy code!
So, See ya!
0 件のコメント:
コメントを投稿