How to identify and correct the logical error? - javascript

Can someone help me finding the logical error in the code bellow?
When it runs, the program displays all as "not guilty" despite one of the objects in the array satisfies the condition.
var suspectsArray = [
{
"name": "BRIDGET ASHELY",
"glasses": "very thick",
"accessory": "metal briefcase",
"eyes": "pale",
"height": 155,
"age": 63
},
{
"name": "LIANNE NIEMELA",
"glasses": "blue",
"accessory": "plastic box",
"eyes": "brown",
"height": 150,
"age": 47
},
{
"name": "JAUNITA FORSLIN",
"glasses": "dark brown",
"accessory": "laptop bag",
"eyes": "grey",
"height": 182,
"age": 58
},
{
"name": "JULIANA DEAUVILLE",
"glasses": "red",
"accessory": "glass bottle",
"eyes": "green",
"height": 175,
"age": 34
},
{
"name": "LINETTE DORCEY",
"glasses": "light tan",
"accessory": "big black envelope",
"eyes": "blue",
"height": 178,
"age": 43
}
];
var myFont;
var backgroundImg;
function preload() {
myFont = loadFont('SpecialElite.ttf');
backgroundImg = loadImage("Background.png");
}
function setup()
{
createCanvas(640,480);
textFont(myFont);
}
function matchSuspect(suspectObj){
for (var k = 0; k < suspectsArray.length; k++)
{
if(
suspectsArray[k].glasses == "blue" &&
suspectsArray[k].accessory == "plastic box" &&
suspectsArray[k].eyes == "brown" &&
suspectsArray[k].height > 141 &&
suspectsArray[k].age < 49
){
return true;
}
return false;
}
}
function draw()
{
image(backgroundImg, 0, 0);
for(let i = 0 ; i < suspectsArray.length; i++){
if(matchSuspect(suspectsArray[i]) == true){
fill(255,0,0);
text(suspectsArray[i].name + " is guilty!", 60, 60 + i * 20);
}else{
fill(0,155,0);
text(suspectsArray[i].name + " is not guilty", 60, 60 + i * 20 );
}
}
}
If running correctly, it should display the second object in the array in red.
I am not sure if the iterations are wrong or what. To experiment with that I tried using || instead of && and the logic was correct (or so the program gave the right answers).
It looks to me like a simple solution, but I spend a very long time on it and couldn't get to it :/

The issue here is that your function ignores the object passed in as a parameter and instead loops through the entire array, but will return as soon as the first person is checked, hence why you are always getting false for every person passed in as a parameter.
To fix this, try removing your for loop inside the function and only process the object being passed in as the parameter instead.
function matchSuspect(suspectObj){
if(
suspectObj.glasses == "blue" &&
suspectObj.accessory == "plastic box" &&
suspectObj.eyes == "brown" &&
suspectObj.height > 141 &&
suspectObj.age < 49
){
return true;
}
return false;
}

matchSuspect() should only test the one subject that's passed in suspectObj.
function matchSuspect(suspectObj) {
return suspectObj.glasses == "blue" &&
suspectObj.accessory == "plastic box" &&
suspectObj.eyes == "brown" &&
suspectObj.height > 141 &&
suspectObj.age < 49;
}

matchSuspect - pass suspects and suspect to it, for better code quality.
draw - pass suspects and matchSuspect to it
use === not ==
fix your styling, would be easier to see.
you loop twice, once in matchSuspect and once in draw, remove the loop from one of them.
You need an else after your true, you return false after the first element in your array.

In the matchSuspect function, when the first iteration runs for the first object of the array, the condition in the if is false and so it gets to the return false; expression and the entire function ends and you don't get to do the other iterations. Basically this means that the function always returns false.
Furthermore, you don't really use the matchSuspect function's parameter suspectObj. Did you mean to do something else?
Maybe you wanted to do something like this?
function matchSuspect(suspectObj) {
if (suspectObj.glasses == "blue" &&
suspectObj.accessory == "plastic box" &&
suspectObj.eyes == "brown" &&
suspectObj.height > 141 &&
suspectObj.age < 49
) {
return true;
}
return false;
}
function draw() {
image(backgroundImg, 0, 0);
for(let i = 0 ; i < suspectsArray.length; i++) {
if (matchSuspect(suspectsArray[i]) == true) {
fill(255,0,0);
text(suspectsArray[i].name + " is guilty!", 60, 60 + i * 20);
} else {
fill(0,155,0);
text(suspectsArray[i].name + " is not guilty", 60, 60 + i * 20 );
}
}
}

Related

How can i write many "OR" in one "IF" javascript

How can i write many "OR" in one "IF" javascript? This code is wrong:
if (d.getMinutes().toString() == 1 || 21 || 31 || 41 || 51){
Something happen
}
You can transform your problem to something like this
Store the values you want to compare in array and pass into includes() the original value to achieve that.
if ([1,21,31,41,51].includes(d.getMinutes())){
Something happen
}
In Javascript, each individual condition must evaluate to a boolean.
var dMinutes = d.getMinutes().toString();
if (dMinutes == 1 || dMinutes == 21 || dMinutes == 31 || dMinutes == 41 || dMinutes == 51){
Something happen
}
If you don't want to repeat d.getMinutes().toString() in your if, it's common approach to use an array and includes() for that purpose:
if ([1, 21, 31, 41, 51].includes(d.getMinutes()) {
Note that toString() is redundant in this case.
let dMinutes = d.getMinutes().toString();
if ( dMinutes == 1 || dMinutes == 21 || dMinutes == 31 || dMinutes == 41 || dMinutes == 51 ) {
Something happen
}
You could do:
if ([1, 21, 31, 41, 51].indexOf(d.getMinutes()) !== -1){
Something happen
}
The toString would not help because the array are numbers
There might be better solutions though.
Another way of doing the same with cleaner code (you don't need toString here):
var d = new Date(2010, 1, 1, 10, 21, 0);
if ([1, 21, 31, 41, 51].includes(d.getMinutes())) {
// do something
console.log("21 minutes");
}
var d2 = new Date(2010, 1, 1, 10, 25, 0);
if ([1, 21, 31, 41, 51].includes(d2.getMinutes())) {
// do something
console.log("This is not executed");
}
This is something I did for a project that you might find useful. This applies with user input, but I'm also sure it could be transformed to match what it is you're doing! try using "else if" instead of "or" for multiple options.
function yourFunction(str) {
len = str.length;
mod = len % 4;
if (mod === 0) {
return "Option 1"
}
else if (mod === 1) {
return "Option 2"
}
else if (mod === 2) {
return "Option 3"
}
else if (mod === 3) {
return "Option 4"
}
}
In your specific case, you could simply the modulo operator:
if (d.getMinutes() % 10 == 1){
// Something happens
}
since every minute value that you listed ends with 1, and you listed all the possible values ending with 1.

Running a function on an Array of Arrays - js

I am trying to take the average of 3 grades for three student (stored in an array of arrays), and then run those averages through a function with an else if statement to check whether the average grades are each and A,B or C.
I would prefer not to have to make a separate function with an else if for each students average (so I would know how to scale this to more than 3 inputs), and I am not sure how I can index the averageGrades array in the function so that I can console.log each element (student) of the averageGrades array and have the else if statement evaluate that particular element (student).
I also tried making an averageGrade variable for each student so that the averageGrades array had single values and not a full equation but ran into the same problem.
var studentGrades = [
[80, 90, 94],
[80, 90, 94],
[80, 90, 94]
]
var studentAvgerages = [
(studentGrades[0][0] + studentGrades[0][1] + studentGrades[0][2]) / 3,
(studentGrades[1][0] + studentGrades[1][1] + studentGrades[1][2]) / 3,
(studentGrades[2][0] + studentGrades[2][1] + studentGrades[2][2]) / 3
]
for (var i = 0; i <= studentAvgerages.length; i++) {
function evalGrades(studentAvgerages[i]) {
if (studentAvgerages[i] >= 90) {
return "A"
} else if ((studentAvgerages[i] >= 80) && (studentAvgerages[i] < 90)) {
return "B"
} else if ((studentAvgerages[i] >= 70) && (studentAvgerages[i] < 80)) {
return "C"
} else {
return "Failed"
}
}
}
console.log(evalGrades(studentAvgerages[0]))
console.log(evalGrades(studentAvgerages[1]))
console.log(evalGrades(studentAvgerages[2]))
Thought I knew what you were looking for, less sure now, but hope this helps a little, somehow? As others have shown, there are some one liners to arrive at your average, if that's what you want.
var studentGrades = [
[80, 90, 94],
[80, 90, 94],
[80, 90, 94]
]
for(var i=0; i < studentGrades.length; i++){
var avg = 0;
for(var j=0; j < studentGrades[i].length; j++){
avg += studentGrades[i][j];
}
avg = avg/studentGrades[i].length;
switch(true){
case (avg >= 90):
console.log("A");
break;
case (avg >= 80):
console.log("B");
break;
case (avg >= 70):
console.log("C");
break;
case (avg >= 60):
console.log("D");
break;
default:
"Failed";
break;
}
}
I prefer switch...case for tasks like this a lot of times, but don't forget to take into account performance. On an array of 20,000 sets of 200 student grades, might be worth using if/else to maintain speed of page. See this answer for more details.
You could take an exit early approach fro getting the grade. No else parts are necessary bycause of the return statement.
For getting the average, you could take a dynamic approach with adding values and divide by the length of the array.
const
add = (a, b) => a + b,
getAverage = array => array.reduce(add, 0) / array.length,
evalGrades = grade => {
if (grade >= 90) return "A";
if (grade >= 80) return "B";
if (grade >= 70) return "C";
return "Failed";
},
studentGrades = [[80, 90, 94], [80, 70, 60], [76, 82, 91]],
studentAvgerages = studentGrades.map(getAverage);
console.log(...studentAvgerages);
console.log(...studentAvgerages.map(evalGrades));
If you are new at programming or javascript, practice some basic examples first and try to understand how the code should be structured in a way you can manage and reuse it. Basically functional programming at least.
From what I understood from your code, you need something that can dynamically calculate the grades of the students.
I have re rewritten the code hope that helps. Also, try to debug the code on your own so as to figure out how the code flows.
var studentGrades = [
[80, 90, 94],
[80, 90, 94],
[80, 90, 94]
]
function evalGrades(grades) {
var sum = 0;
for(var i =0; i<grades.length; i++){
sum = sum + grades[i];
}
var avg = sum/grades.length;
if (avg >= 90) {
return "A"
} else if ((avg >= 80) && (avg < 90)) {
return "B"
} else if ((avg >= 70) && (avg < 80)) {
return "C"
} else {
return "Failed"
}
}
for (var i = 0; i < studentGrades.length; i++) {
console.log(evalGrades(studentGrades[i]))
}
Try this. I hope I've been helpful.
var studentGrades = [
[80, 90, 94],
[80, 90, 94],
[80, 90, 94]
]
for (var i = 0; i < studentGrades.length; i++) {
var average = studentGrades[i].reduce((a, b) => a + b, 0) / studentGrades[i].length;
if (average >= 90) { var result = "A" }
else if ( average >= 80 && average < 90 ) { var result = "B" }
else if ( average >= 70 && average < 80 ) { var result = "C" }
else { var result = "Failed" }
console.log(result);
}

Determine a winner with if / else

Can anyone help me out and explain to me how I can use operators inside an if / else statement, I am trying to do something simple and get a result of two different multiplications, I'm a self taught developer so please bear with me
var oscar = {
height: 155,
age: 22,
};
var andrew = {
height: 170,
age: 16,
};
if ((oscar * 5) > (andrew * 5)) {
console.log('Oscar is the winner');
} else if ((oscar * 5) < (andrew * 5)) {
console.log('Andrew is the winner')
} else {
console.log('No winner')
}
Variables are objects, you must specify the property of comparison.
No need to multiply by 5.
var oscar = {
height: 155,
age: 22
};
var andrew = {
height: 170,
age: 16
};
if ((oscar.height) > (andrew.height)) {
console.log('Oscar is the winner');
} else if ((oscar.height) < (andrew.height)) {
console.log('Andrew is the winner')
} else {
console.log('No winner')
}
You cannot compare objects like that.
Perhaps you wanted to assign some points? Then add another property which you CAN calculate on
Also no need to multiply by anything if you multiply both sides of the equal sign with the same number
You could do this:
function scoreIt(p1,p2) {
var diff = p1.points - p2.points;
console.log("diff", diff);
if (diff > 0) {
console.log(p1.name+ ' is the winner with ' + p1.points);
} else if (diff < 0) {
console.log(p2.name + ' is the winner with ' + p2.points);
} else {
console.log('No winner - tied score ' + p1.points);
}
}
var participant1 = {
name: "Oscar",
height: 155,
age: 22,
points: 8 // no trailing comma
};
var participant2 = {
name: "Andrew",
height: 170,
age: 16 // no trailing comma
};
// later somewhere:
participant2.points = 9; // assignment
scoreIt(participant1,participant2);
participant1.points += 5; // increase
scoreIt(participant1,participant2);
participant2.points += 4;
scoreIt(participant1,participant2);
The object would be even better if you use the names as keys:
var participants = {
"Oscar": {
height: 155,
age: 22,
points: 8 // no trailing comma
},
"Andrew" : {
height: 170,
age: 16 // no trailing comma
}
}

Conditional If Statement with change in method

I have this function that is supposed to loop through these additional functions while they won't take the totals up past 100. However, the iteration stops and I need it to finish up with the hunger and danger value either being 100 or 0 depending on which. The numbers that pass through are first: (50,50) second: (0, 100). I can't seem to figure out how to change the addition/subtractions amount when the if condition is no longer met. My consoles are all displaying the last iteration before going over the conditional values.
The problem is:
Create a function called frodo. frodo will take in two parameters:
startingHungerValue (Number) and startingDangerValue (Number).
frodo will need to store those values on internal variables.
frodo will then return an object with two methods:
The first method will be called dinnerOverFire.
dinnerOverFire will decrease hunger by 25 and will increase danger by 40.
The second method will be called hidingInBush.
hidingInBush will increase hunger by 35 and decrease danger by 20.
Both methods need to return an object structured like this:
{
hunger: (modified hunger value),
danger: (modified danger value)
}
NOTE: Neither hunger nor danger should be able to exceed 100 or drop below 0.
function frodo(startingHungerValue, startingDangerValue) {
var shv = startingHungerValue;
var sdv = startingDangerValue;
console.log('startingHungerValue:', shv, 'startingDANGERvalue:', sdv)
return {
dinnerOverFire: () => {
if ((shv >= 0 && shv < 101) && (sdv >= 0 && sdv < 101)) {
return {
hunger: shv - 25,
danger: sdv + 40
}
}
},
hidingInBush: () => {
if ((shv >= 0 && shv < 101) && (sdv >= 0 && sdv < 101)) {
return {
hunger: shv + 35,
danger: sdv - 20
}
}
}
}
}
Not directly what you asked for, but I have a feeling you want to do something like below. It creates a class Frodo that you can call methods on like eat or hide.
You can see it in action here: jsfiddle
function Frodo(startingHungerValue, startingDangerValue) {
var self = this; //this could change per scope, self keeps a reference to the basic of the class
//store levels
self.hunger = startingHungerValue;
self.danger = startingDangerValue;
//show levels method
self.showLevels = function(){
console.log('My hungerlevel: '+ self.hunger);
console.log('My dangerlevel: '+ self.danger);
console.log('------');
}
//dinner method
self.dinnerOverFire = function() {
var newHunger = self.hunger - 25;
var newDanger = self.danger + 40;
if (newHunger<0) {
newHunger = 0; //no negatives
}
if (self.hunger==0) {
console.log('I\'m not hungry! No dinner!');
console.log('------');
return;
}
if (newDanger>100) {
console.log('Eating now would kill me! No dinner!');
console.log('------');
return;
}
self.hunger = newHunger;
self.danger = newDanger;
console.log('Thanks for dinner!');
self.showLevels();
}
//hiding method
self.hideInBush = function() {
var newHunger = self.hunger + 35;
var newDanger = self.danger - 20;
if (newDanger<0) {
newDanger = 0; //no negatives
}
if (newHunger>100) {
console.log('Hiding now would kill me! No hiding!');
console.log('------');
return;
}
if (self.danger==0) {
console.log('I\'m not scared at all! No hiding!');
console.log('------');
return;
}
self.hunger = newHunger;
self.danger = newDanger;
console.log('Thanks, I feel safer already!');
self.showLevels();
}
//initial message
console.log('Hi, i\'m frodo!');
self.showLevels();
}
//run your frodo
var frodo = new Frodo(50,50);
frodo.dinnerOverFire();
frodo.hideInBush();
frodo.dinnerOverFire();
frodo.hideInBush();
frodo.dinnerOverFire();
frodo.hideInBush();
frodo.dinnerOverFire();
This would output:
Hi, i'm frodo!
My hungerlevel: 50
My dangerlevel: 50
------
Thanks for dinner!
My hungerlevel: 25
My dangerlevel: 90
------
Thanks, I feel safer already!
My hungerlevel: 60
My dangerlevel: 70
------
Eating now would kill me! No dinner!
------
Thanks, I feel safer already!
My hungerlevel: 95
My dangerlevel: 50
------
Thanks for dinner!
My hungerlevel: 70
My dangerlevel: 90
------
Hiding now would kill me! No hiding!
------
Eating now would kill me! No dinner!
------
Which already shows a problem with the current way. At the end he's to scared to eat and to hungry to hide.
Do you mean, adding an else block to the if condition?
function frodo(startingHungerValue, startingDangerValue) {
var shv = startingHungerValue;
var sdv = startingDangerValue;
console.log('startingHungerValue:', shv, 'startingDANGERvalue:', sdv)
return {
dinnerOverFire: () => {
if ((shv === 50 && shv === 50)){
return {
hunger: shv - 50,
danger: sdv + 50
}
}
else if ((shv >= 0 && shv < 101) && (sdv >= 0 && sdv < 101)) {
return {
hunger: shv + 100,
danger: sdv - 100
}
}
},
hidingInBush: () => {
if ((shv === 50 && shv === 50)){
return {
hunger: shv - 50,
danger: sdv + 50
}
}
else if ((shv >= 0 && shv < 101) && (sdv >= 0 && sdv < 101)) {
return {
hunger: shv + 100,
danger: sdv - 100
}
}
}
}
}
console.log(frodo(50, 50).dinnerOverFire()); // 0,100
console.log(frodo(0, 100).dinnerOverFire()); // 100,0
.as-console {
height: 100%;
}
.as-console-wrapper {
max-height: 100% !important;
top: 0;
}

Check if more than two date ranges overlap

I have multiple date ranges. I want to check if they are overlapping in javascript. When there are only two it is easy, I use:
if(start_times1 <= end_times2 && end_times1 >= start_times2) {}
But what is the formula when there are more than 2 date ranges?
You can use nested for loops with arguments
function dateRangeOverlaps(a_start, a_end, b_start, b_end) {
if (a_start <= b_start && b_start <= a_end) return true; // b starts in a
if (a_start <= b_end && b_end <= a_end) return true; // b ends in a
if (b_start < a_start && a_end < b_end) return true; // a in b
return false;
}
function multipleDateRangeOverlaps() {
var i, j;
if (arguments.length % 2 !== 0)
throw new TypeError('Arguments length must be a multiple of 2');
for (i = 0; i < arguments.length - 2; i += 2) {
for (j = i + 2; j < arguments.length; j += 2) {
if (
dateRangeOverlaps(
arguments[i], arguments[i+1],
arguments[j], arguments[j+1]
)
) return true;
}
}
return false;
}
Here is refined version of what Paul posted:
Added filter and null check to allow any number of entries
Changed the logic so that it can be applied on an array. Eg: [{"from": value, "to": value}]
Adjusted overlap check to allow times having end and start as same
Script:
function dateRangeOverlaps(a_start, a_end, b_start, b_end) {
if (a_start < b_start && b_start < a_end) return true; // b starts in a
if (a_start < b_end && b_end < a_end) return true; // b ends in a
if (b_start < a_start && a_end < b_end) return true; // a in b
return false;
}
function multipleDateRangeOverlaps(timeEntries) {
let i = 0, j = 0;
let timeIntervals = timeEntries.filter(entry => entry.from != null && entry.to != null && entry.from.length === 8 && entry.to.length === 8);
if (timeIntervals != null && timeIntervals.length > 1)
for (i = 0; i < timeIntervals.length - 1; i += 1) {
for (j = i + 1; j < timeIntervals.length; j += 1) {
if (
dateRangeOverlaps(
timeIntervals[i].from.getTime(), timeIntervals[i].to.getTime(),
timeIntervals[j].from.getTime(), timeIntervals[j].to.getTime()
)
) return true;
}
}
return false;
}
Below code comes from my project, maybe it will help you:
function dateRangeOverlaps(startDateA, endDateA, startDateB, endDateB) {
if ((endDateA < startDateB) || (startDateA > endDateB)) {
return null
}
var obj = {};
obj.startDate = startDateA <= startDateB ? startDateB : startDateA;
obj.endDate = endDateA <= endDateB ? endDateA : endDateB;
return obj;
}
//storing existing dates for comparison
public multipleExistingDates=[
{startDate:'02/03/2020 05:00:00',endDate:'02/03/2020 05:30:00'},
{startDate:02/04/2020 05:00:00'',endDate:'02/05/2020 05:00:00'},]
/The date to be compared with existing dates to check if the new date is overlapping with existing dates/
public checkOverlappingDsates(startDate:Date, endDate:Date):boolean{
return this.multipleExistingDates.some((elem)=>{
return( !((moment(endDate).diff(moment(elem.startDate))) < 0 ||
(moment(startDate).diff(moment(elem.endDate))) > 0;})
Note: If the date is overlapping, the function return true else false. Also , you would need to install moment for date comparison.
Why don't we use moment and moment-range, is it not supported across all browsers? 🤔
window['moment-range'].extendMoment(moment);
const events1 = [{
"Date": "05/15/2021",
"EndTime": "17:00",
"StartTime": "16:00"
},
{
"Date": "05/15/2021",
"EndTime": "18:00",
"StartTime": "17:00"
},
{
"Date": "05/15/2021",
"EndTime": "18:45",
"StartTime": "17:45"
}
];
const events2 = [{
"Date": "05/15/2021",
"EndTime": "17:00",
"StartTime": "16:00"
},
{
"Date": "05/15/2021",
"EndTime": "18:00",
"StartTime": "17:00"
},
{
"Date": "05/15/2021",
"EndTime": "19:45",
"StartTime": "18:45"
}
];
function checkOverlap(timeSegments) {
var overlap = timeSegments
.map(r =>
timeSegments.filter(q => q != r).map(q =>
moment.range(
moment(q.Date + " " + q.StartTime),
moment(q.Date + " " + q.EndTime)
).overlaps(
moment.range(
moment(r.Date + " " + r.StartTime),
moment(r.Date + " " + r.EndTime)
)
)
)
);
console.log(overlap.map(x => x.includes(true)).includes(true));
}
checkOverlap(events1);
checkOverlap(events2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-range/4.0.2/moment-range.js"></script>
Simply use the areIntervalsOverlapping function from date-fns, the "modern JavaScript date utility library".
You just have to pass the two dates as arguments to the function, and it will return true or false depending if the two dates overlaps or not.
Example
Check this example from their documentation:
areIntervalsOverlapping(
{ start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
{ start: new Date(2014, 0, 17), end: new Date(2014, 0, 21) }
)
//=> true
This example above returned true because the two dates overlaps. Note that the 0 number (the second argument) in Date(2014, 0, 10) represents the month of January.
You can also use this areIntervalsOverlapping function to check if other time intervals (like hours in the same day) overlaps, because in JavaScript a Date object also considers hours.
Installation
If, for example, you are using Node.js (or any framework that uses it), you just have to install date-fns with
npm install date-fns --save
And then import the desired functions inside your JavaScript code like:
import { areIntervalsOverlapping } from "date-fns";
Of course date-fns is not limited to Node.js. You can use it inside any JavaScript project.
Wouldn't be too hard to do recursively. Make a method overlap which returns the overlapping daterange for two dates. Then in your hasOverlap(list dates) method, if the list is two items, it's simple, else, return hasoverlap(overlap(dates[0], dates[1]), rest of list)
No matter the language, the basic logic to see if two date ranges overlap is:
max(range_1_start, range_2_start) <= min(range_1_end, range_2_end)
In JavaScript syntax, that might look like this:
function doDatesOverlap(start_1,end_1,start_2,end_2){
return Math.max(start_1,start_2) <= Math.min(end_1,end_2);
}
var start_1 = new Date('01/01/2023');
var end_1 = new Date('01/31/2023');
var start_2 = new Date('01/15/2023');
var end_2 = new Date('02/15/2023');
if(doDatesOverlap(start_1,end_1,start_2,end_2)){
console.log('They overlap!');
}

Categories