Skip to content

Instantly share code, notes, and snippets.

@angelo-moreira
Created April 27, 2018 13:14
Show Gist options
  • Save angelo-moreira/a03fda14665f2a938073a0f841c54178 to your computer and use it in GitHub Desktop.
Save angelo-moreira/a03fda14665f2a938073a0f841c54178 to your computer and use it in GitHub Desktop.
interview file
<?php
/*
You will write some functions related to calendar dates. In all problems, a “date” is an array of type [int*int*int], where the first part is the year, the second part is the month, and the third part is the day. A “reasonable” date has a positive year, a month between 1 and 12, and a day no greater than 31 (or less depending on the month).
Your solutions need to work correctly only for reasonable dates, checking for reasonable dates it's not required.
1 - Write a function is_older that takes two dates and evaluates to true or false. Use the $dates array as input.
It evaluates to true if the first argument is a date that comes before the second argument. (If the two dates are the same, the result is false.)
2 - Write a function number_in_month that takes an array of dates and a month (i.e., an int) and returns how many dates in the array are in the given month. Use the $dates array as input.
3 - Write a function dates_in_month_nested that takes a multidimensional array of dates and a month (i.e., an int) and returns an array holding the dates from the argument array of dates that are in the month. The returned array should contain all dates including nested dates. Use the $nested_dates array as input.
Hints: You might need use array_merge but that's not a pre-requisite
*/
$dates = [
[1980,12,16],
[1980,04,23],
[2012,2,28],
[2013,12,1],
[1980,12,21],
[2011,3,31],
[2011,4,28],
[2,3,4],
[2012,4,28],
[2011,2,31],
[2011,5,28]
];
$nested_dates = [
[1980,12,16],
[1980,04,23],
[2012,2,28],
[2013,12,1],
[1980,12,21],
[
[2011,1,31],
[2011,3,28],
[
[2013,10,31],
[2016,1,14]
]
],
[2,3,4],
[2012,1,28],
[2011,2,31],
[2011,1,28]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment