Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You have a list of birthdays. People born on 25.05.1973 and after are fans of Ewoks and these before that
- – haters. The biggest hater is the oldest person born before 25.05.1973. The biggest fan is the youngest person
- born after 25.05.1973. Find the biggest fan and hater of Ewoks. Exclude people born on or before 01.01.1900 and
- those born on and after 01.01.2015, because most of them are either dead or not born yet.
- The input data comes as array of strings containing dates in the format “dd.mm.yyyy”.
- Print at the console when the biggest fan and the biggest hater of Ewoks were born.
- Use the method "date.toDateString()" to format the date at the output.
- If there is only one fan or hater, print out the date of his birth. If there are no people between 01.01.1900
- and 01.01.2015 print “No result”. */
- "use strict";
- function printFansAndHatersOfTheEwoks(args) {
- var bornDatesArr = [];
- for (var i = 0; i < args.length; i += 1) {
- var dateStr = args[i].split('.').filter(Boolean);
- var bornOnDate = new Date(dateStr[2] + '-' + dateStr[1] + '-' + dateStr[0]);
- if (bornOnDate > new Date('1900-01-01') && bornOnDate < new Date('2015-01-01')) {
- bornDatesArr.push(bornOnDate);
- }
- }
- if (bornDatesArr.length > 1) {
- bornDatesArr.sort(function (date1, date2) {
- return (date1 > date2) ? 1 : (date1 < date2) ? -1 : 0;
- });
- }
- var borderDate = new Date('1973-05-25');
- if (!bornDatesArr.length) {
- console.log('No result');
- } else {
- if (bornDatesArr[bornDatesArr.length - 1] >= borderDate) {
- console.log('The biggest fan of ewoks was born on ' +
- bornDatesArr[bornDatesArr.length - 1].toDateString());
- }
- if (bornDatesArr[0] < borderDate) {
- console.log('The biggest hater of ewoks was born on ' +
- bornDatesArr[0].toDateString());
- }
- }
- }
- printFansAndHatersOfTheEwoks(['22.03.2014', '17.05.1933', '10.10.1954']);
- printFansAndHatersOfTheEwoks(['22.03.2000']);
- printFansAndHatersOfTheEwoks(['22.03.1700', '01.07.2020']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement