Sometimes, there isn’t a good choice and we need to choose the lesser evil.
Implement a function getLesserEvil that takes two objects, compares them by the field evilFactor and
returns the one with the smallest evilFactor.
This task is part of the Full-Stack JavaScript Course
If you have any issues with it, you can ask for community help below the post
Feel free to help others if you’ve already solved the task
helper.js
export const getLesserEvil = (threat1, threat2) => {
return threat1;
}
solution.js
/**
* Sometimes, there isn't a good choice and we need to choose the lesser evil.
*
* Implement a function **getLesserEvil** that takes two objects, compares them by the field **evilFactor** and
* returns the one which the smaller **evilFactor**.
* */
import { getLesserEvil } from './helper.js';
const globalWarming = {
description: 'Global warming risk',
evilFactor: 10,
}
const aiThreat = {
description: 'The AI threat to humanity',
evilFactor: 1,
}
const globalPandemic = {
description: 'Mass extinction from the global pandemic',
evilFactor: 3,
}
console.log(getLesserEvil(globalWarming, globalPandemic));
console.log(getLesserEvil(aiThreat, globalPandemic));