Closed RazvanBugoi closed 4 years ago
function iTri(s){
let totalDistance = 140.6;
if(s == 0) return 'Starting Line... Good Luck!';
if(s <= 2.4) return {'Swim':`${(totalDistance - s).toFixed(2)} to go!`};
if(s <= 114.4) return {'Bike':`${(totalDistance - s).toFixed(2)} to go!`};
if(s <= 140.6 && (totalDistance - s) > 10) return {'Run':`${(totalDistance - s).toFixed(2)} to go!`};
if(s <= 140.6 && (totalDistance - s) < 10) return {'Run':'Nearly there!'};
return "You're done! Stop running!"
}
De optimizat solutia
function iTri(s){
let totalDistance = 140.6;
let arr = [{'Swim':`${(totalDistance - s).toFixed(2)} to go!`},
{'Bike':`${(totalDistance - s).toFixed(2)} to go!`},
{'Run':`${(totalDistance - s).toFixed(2)} to go!`},
{'Run':'Nearly there!'}
];
if(s ==0 ) return 'Starting Line... Good Luck!';
if(s <= 2.4) return arr[0];
if(s <= 114.4) return arr[1];
if(s <= 140.6 && (totalDistance - s) > 10) return arr[2];
if(s <= 140.6 && (totalDistance - s) < 10) return arr[3];
return "You're done! Stop running!";
}
https://www.codewars.com/kata/57d001b405c186ccb6000304/train/javascript