Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-kovalchuk committed Apr 16, 2024
1 parent 456bf4f commit 352d24d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/formatDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,29 @@
* @returns {string}
*/
function formatDate(date, fromFormat, toFormat) {
// write code here
const object = {};
const splitDate = date.split(fromFormat[fromFormat.length - 1]);
const result = [];

for (let i = 0; i < fromFormat.length - 1; i++) {
object[fromFormat[i]] = splitDate[i];
}

if (object.hasOwnProperty('YYYY')) {
object.YY = object.YYYY.slice(2);
}

if (object.YY >= 30) {
object.YYYY = '19' + object.YY;
} else {
object.YYYY = '20' + object.YY;
}

for (let i = 0; i < toFormat.length - 1; i++) {
result.push(object[toFormat[i]]);
}

return result.join(toFormat[toFormat.length - 1]);
}

module.exports = formatDate;

0 comments on commit 352d24d

Please sign in to comment.