function searchReportsByTitle(title) { var matchingReports = []; for (var i = 0; i < reports.length; i++) { if (reports[i].title.toLowerCase().includes(title.toLowerCase())) { matchingReports.push(reports[i]); } } return matchingReports; }
// Function to search for reports by author
function searchReportsByAuthor(author) { var matchingReports = []; for (var i = 0; i < reports.length; i++) { if (reports[i].author.toLowerCase().includes(author.toLowerCase())) { matchingReports.push(reports[i]); } } return matchingReports; }
// Function to search for reports published within a date range
function searchReportsByDateRange(startDate, endDate) { var matchingReports = []; for (var i = 0; i < reports.length; i++) { var publicationDate = new Date(reports[i].publicationDate); if (publicationDate >= startDate && publicationDate <= endDate) { matchingReports.push(reports[i]); } } return matchingReports; }
// Usage example:
// Add reports to the database
addReport("Market Analysis Report", "John Doe", "2023-05-01", "This report provides an in-depth analysis of the current market trends."); addReport("Consumer Behavior Study", "Jane Smith", "2023-06-15", "This study explores consumer preferences and behavior in the digital age.");
// Search for reports by title
var matchingReports = searchReportsByTitle("market"); console.log(matchingReports);
// Search for reports by author
var authorReports = searchReportsByAuthor("john"); console.log(authorReports);
// Search for reports published within a date range
var startDate = new Date("2023-05-01"); var endDate = new Date("2023-06-30"); var dateRangeReports = searchReportsByDateRange(startDate, endDate); console.log(dateRangeReports);