All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2701_2800.s2722_join_two_arrays_by_id.solution.ts Maven / Gradle / Ivy

There is a newer version: 1.35
Show newest version
// #Medium #2023_09_18_Time_246_ms_(96.81%)_Space_106_MB_(70.44%)

function join(arr1: any[], arr2: any[]): any[] {
    const result: any = {}
    for (let obj of arr1) {
        result[obj.id] = obj
    }
    for (let obj of arr2) {
        if (result[obj.id]) {
            for (let key in obj) {
                result[obj.id][key] = obj[key]
            }
        } else {
            result[obj.id] = obj
        }
    }
    return Object.values(result)
}

export { join }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy