Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Even the Last by dstarod
"use strict";
function evenLast(data) {
if(data.length == 0) return 0;
return data
.filter(function(x, n){return n%2==0;})
.reduce(function(x, y){return x+y;}, 0) * data[data.length - 1];
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(evenLast([0, 1, 2, 3, 4, 5]), 30, "(0+2+4)*5=30");
assert.equal(evenLast([1, 3, 5]), 30, "(1+5)*5=30");
assert.equal(evenLast([6]), 36, "(6)*6=36");
assert.equal(evenLast([]), 0, "An empty array = 0");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Sept. 20, 2016
Comments: