1var reformatDate = function (date) {2const ans = [];3const month = [4"Jan",5"Feb",6"Mar",7"Apr",8"May",9"Jun",10"Jul",11"Aug",12"Sep",13"Oct",14"Nov",15"Dec",16];1718const [inputDate, inputMonth, inputYear] = date.split(" ");19ans.push(inputYear);20ans.push("-");2122const monthIndex = month.findIndex((mon) => mon === inputMonth);23const formatedMonth = String(monthIndex + 1).padStart(2, "0");24ans.push(formatedMonth);25ans.push("-");2627const slicedDate = inputDate.slice(0, 2);28if (+slicedDate >= 10) {29ans.push(slicedDate);30} else {31const formatedDate = inputDate.slice(0, 1).padStart(2, "0");32ans.push(formatedDate);33}3435return ans.join("");36};