Answer to Question #302844 in HTML/JavaScript Web Application for sreenu

Question #302844

The function accepts two positive integers ‘r’ and ‘unit’ and a positive integer array ‘arr’ of size ‘n’ as its argument ‘r’ represents the number of rats present in an area, ‘unit’ is the amount of food each rat consumes and each ith element of array ‘arr’ represents the amount of food present in ‘i+1’ house number, where 0 <= i


1
Expert's answer
2022-02-25T17:37:21-0500
function func(r, unit, arr) {
    const needFood = r * unit
    const suppliesFood = arr.map(i => x += i, x = 0).reverse()[0]
    if (needFood <= suppliesFood) {
        return 'Enough food for the rats'
    } else {
        return "The rats don't have enough food"
    }
}

console.log(func(10, 5, [20, 16, 5, 10, 12, 3]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS