Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Sum by Type solution in Uncategorized category for Sum by Type by vvm70
import assert from "assert";
function sumByTypes(values) {
let lst = ['', 0];
for(let value of values)
lst[Number(typeof value == 'number')] += value;
return lst;
}
console.log('Example:');
console.log(sumByTypes([]));
// These "asserts" are used for self-checking
assert.deepEqual(sumByTypes([]), ['', 0]);
assert.deepEqual(sumByTypes([1, 2, 3]), ['', 6]);
assert.deepEqual(sumByTypes(['1', 2, 3]), ['1', 5]);
assert.deepEqual(sumByTypes(['1', '2', 3]), ['12', 3]);
assert.deepEqual(sumByTypes(['1', '2', '3']), ['123', 0]);
assert.deepEqual(sumByTypes(['size', 12, 'in', 45, 0]), ['sizein', 57]);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
July 5, 2020
Comments: