0% found this document useful (0 votes)
7 views

Sample Code

Uploaded by

Abhishek Sonar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Sample Code

Uploaded by

Abhishek Sonar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

var reports = [];

// Report data structure


var Report = {
title: "",
author: "",
publicationDate: "",
content: ""
};

// Function to add a report to the database


function addReport(title, author, publicationDate, content) {
var report = Object.create(Report);
report.title = title;
report.author = author;
report.publicationDate = publicationDate;
report.content = content;
reports.push(report);
}

// Function to search for reports by title


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);

You might also like