docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Build a configuration merger utility that combines multiple configuration objects while properly handling array values. The merger should deeply merge nested configuration objects but preserve array values without merging them.
Create a module that exports a mergeConfigs function that:
The function should handle:
const config1 = {
servers: ['server1.com', 'server2.com'],
port: 8080
};
const config2 = {
servers: ['server3.com'],
timeout: 5000
};
const result = mergeConfigs(config1, config2);
// Expected:
// {
// servers: ['server3.com'], // Replaced, not merged
// port: 8080,
// timeout: 5000
// }const config1 = {
database: {
hosts: ['db1.com', 'db2.com'],
options: { poolSize: 10 }
}
};
const config2 = {
database: {
hosts: ['db3.com'],
options: { timeout: 3000 }
}
};
const result = mergeConfigs(config1, config2);
// Expected:
// {
// database: {
// hosts: ['db3.com'], // Array replaced
// options: { poolSize: 10, timeout: 3000 } // Objects merged
// }
// }const config1 = {
features: {
enabled: ['feature1', 'feature2'],
settings: { mode: 'auto' }
}
};
const config2 = {
features: {
enabled: ['feature3'],
settings: { level: 5 }
}
};
const config3 = {
features: {
settings: { mode: 'manual' }
}
};
const result = mergeConfigs(config1, config2, config3);
// Expected:
// {
// features: {
// enabled: ['feature3'], // From config2 (config3 doesn't override)
// settings: { mode: 'manual', level: 5 } // Deeply merged
// }
// }src/
merger.js # Main implementation
merger.test.js # Test file with the test cases aboveProvides deep object merging capabilities.