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.30
Show newest version
// #Medium #2023_08_02_Time_280_ms_(98.29%)_Space_99.7_MB_(97.43%)

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