Created
May 23, 2021 19:17
-
-
Save crudeboy/95c2e30f7d8613333b69e8f3c7f83d69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// least time differnce in an array | |
function minDiff(arr){ | |
var sortedArr = arr.sort(); | |
var diff = Number.MAX_VALUE; | |
for (let i = 0; i < sortedArr.length - 1; i++){ | |
if(Math.abs(new Date('01/01/2001 ' + sortedArr[i + 1]) - new Date('01/01/2001 ' +sortedArr[i]) < diff )){ | |
diff = new Date('01/01/2001 ' + sortedArr[i + 1]) - new Date('01/01/2001 ' +sortedArr[i]) | |
} | |
} | |
return diff / (1000 * 60) | |
} | |
console.log(minDiff(['16:00','12:20','16:15'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment