Created
August 27, 2024 05:26
-
-
Save Vampeyer/4beab8650026ea6df9cc912676947dd5 to your computer and use it in GitHub Desktop.
JavaScript - Mastery Kata 7 - most plump and most red vegetables , nested obj in array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const vegetables = [ | |
{ | |
submitter: "Old Man Franklin", | |
redness: 10, | |
plumpness: 5, | |
}, | |
{ | |
submitter: "Sally Tomato-Grower", | |
redness: 2, | |
plumpness: 8, | |
}, | |
{ | |
submitter: "Hamid Hamidson", | |
redness: 4, | |
plumpness: 3, | |
}, | |
]; | |
let redMax = 0 | |
let submission; | |
let plumpMax = 0 | |
let submission2; | |
let characteristic = 'redness' | |
function judgeVegtables(vegetables, characteristic){ | |
for ( let i of vegetables){ | |
// console.log(i) | |
if(redMax <= i.redness){ | |
redMax = i.redness; | |
submission = i.submitter | |
} | |
if(plumpMax <= i.plumpness){ | |
plumpMax = i.plumpness; | |
submission2 = i.submitter | |
} | |
} | |
console.log('most redness is' , submission , " Most plumpness " , submission2) | |
if(characteristic === 'redness'){ | |
return submission | |
} | |
if(characteristic === 'plumpness'){ | |
return submission2 | |
}else { | |
return ' Please choose \' Redness \' or \'Plumpness\'.' | |
} | |
} | |
console.log(judgeVegtables(vegetables, characteristic)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment