This file contains 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
// Formatted YYYYMMDDHHMMSS Int for timestamp calculation without needing any extra libs | |
const getFormattedDateTime = (dateObj) => { | |
let verifyDoubleDigits = (vals) => vals.map(val => val.length === 1 ? "0" + val : val) | |
let date = dateObj && dateObj.getMonth === 'function' ? datObj : new Date() | |
let year = date.getFullYear() .toString() | |
let month = (date.getMonth()+1).toString() | |
let day = date.getDate() .toString() | |
let hour = date.getHours() .toString() | |
let minutes = date.getMinutes() .toString() |
This file contains 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
/* Author Aman Meghrajani - amanmeghrajaniatgmaildotcom */ | |
/* Function to find the longest unique path in a Given BST with O(n) complexity */ | |
/* | |
Utility Function - _longestUniquePath | |
Input - Tree object and a cache object to store path count | |
Output - Maximum Path count |
This file contains 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
const getHumanizedDateTime = (yyyymmddhhmmss) => { | |
let components = yyyymmddhhmmss.split(''); | |
let year = components.splice(0,4).join(''); | |
let month = components.splice(0,2).join(''); | |
let day = components.splice(0,2).join(''); | |
let hour = components.splice(0,2).join(''); | |
let minute = components.splice(0,2).join(''); | |
let second = components.join(''); | |
let humanized = `${month}/${day}/${year} - ${hour}:${minute}:${second}`; | |
console.log(humanized); |
This file contains 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
// takes O(log(n) base 2 + 1) iterations where 2 ^ n is the closest to array.count | |
// example 10 is closest to 2^3 which will take 3 + 1 iterations to find an element in the worst case scenario | |
func iterativeBinarySearch (_ array: [Int],_ key: Int) -> Int? { | |
var low = 0; | |
var high = array.count - 1 | |
var mid : Int; | |
// var iterations = 0; |
This file contains 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
/* Author - Aman Meghrajani - amanmeghrajaniatgmaildotcom */ | |
/* Remove Duplicates in a Singly Linked List | |
Input - head Node of SinglyLinkedList | |
Output - void | |
Notes - We will cache all elements that occur once and remove them if they occur again | |
*/ | |
function removeDuplicates (head) { |