Skip to content

Mouaadouk/Reindeer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Riender olumpics

const reindeers =[

{

name :'Blitzen',

vitesse : 19,

flyDuration : 9,

restDuration :158

},

{

name :'Donner',

vitesse : 19,

flyDuration : 9,

restDuration :164

},

{

name :'Rudolph',

vitesse : 3,

flyDuration : 15,

restDuration :28

},

{

name :'Vixen',

vitesse : 19,

flyDuration : 7,

restDuration :124

},

{

name :'comet',

vitesse : 14,

flyDuration : 10,

restDuration :127

},

{

name :'dancer',

vitesse : 16,

flyDuration : 11,

restDuration :162

},

{

name :'prancer',

vitesse : 25,

flyDuration : 6,

restDuration :143

},

{

name :'Dasher',

vitesse : 14,

flyDuration : 3,

restDuration :38

},

{

name :'Cupid',

vitesse : 25,

flyDuration : 6,

restDuration :145

}

]

Function to calculate distance travelled per reindeer

const calculateDistance = (reeinder ,travelingTime )=>{

const traveledSegment = Math.floor(travelingTime/(reeinder.flyDuration + reeinder.restDuration));

const segmentRest = travelingTime% (reeinder.flyDuration + reeinder.restDuration);

return ((traveledSegment*reeinder.flyDuration + Math.min(reeinder.flyDuration ,segmentRest ))*reeinder.vitesse)

}

function return the distance traveled by tha winnings reindeers

const maxDistanceTraveled = (travelingTime , ...reindeers)=>{

let maxDistance = 0;

const winningTraveledDistance = reindeers.reduce((acc,item)=>{

if(calculateDistance(item,travelingTime) > maxDistance){

maxDistance = calculateDistance(item,travelingTime)

acc = item

}

return maxDistance

},{})

return winningTraveledDistance

}

const winningsReindeersDistace = maxDistanceTraveled(2503 , ...reindeers)

console.log(winningsReindeersDistace)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published