/**
 * Linear Interpolation
 */
export const lerp = (start: number, end: number, amt: number): number => {
    return (1 - amt) * start + amt * end
}


/**
 * Return a random element from an array
 */
export const getRandomElement = (array: any[]): any => {
    return ~~(array.length * Math.random())
}


/**
 * Get a DOM element's position
 */
export const getPosition = (node, scope?: HTMLElement) => {
    const root = scope || document
    let offsetTop = node.offsetTop
    let offsetLeft = node.offsetLeft
    while (node && node.offsetParent && node.offsetParent != document && node !== root && root !== node.offsetParent) {
        offsetTop += node.offsetParent.offsetTop
        offsetLeft += node.offsetParent.offsetLeft
        node = node.offsetParent
    }
    return {
        top: offsetTop,
        left: offsetLeft
    }
}