Even and Last

Published by Werdna in

Given an array of integers $arr, return the sum of all the integers that have an even index, multiplied by the integer at the last index.

If the sequence is empty, you should return 0.

Examples

evenLast([2, 3, 4, 5]) ➞ 30
// numbers at even index = 2, 4
// number at last index = 5
// 2*5 + 4*5 = 10 + 20 = 30

evenLast([1, 3, 3, 1, 10]) ➞ 14

evenLast([]) ➞ 0

Notes

N/A

Watch a quick demo on how Edabit works.