When it comes to solving problems in programming languages, the use of a hashset is typically the go-to solution due to its fast lookup times and random access capabilities.
However, in the world of Javascript, things work a bit differently. Instead of a hashset, an object is often used as the simplest way to achieve similar functionality. For example:
var holidays = {
1:true,
7:true,
18:true
}
While days since new year are commonly used, there's no restriction on using other identifiers like dates.
To streamline the process, a helpful function can be created:
var checkDate = function(value){
return holidays[value] === true;
};
Simply calling checkDate(dayOfYear) will efficiently determine if a particular day is a holiday or not. This can then be utilized in various scenarios, such as:
//Although more like pseudocode than actual javascript given my current skill level
while checkDate(--dayOfYear) === true)
previousBusinessDay = dayOfYear;
This demonstrates how an approach using objects in Javascript can efficiently handle tasks that may traditionally be solved with a hashset in other languages.