Mauro Bringolf b83e0ec7b0 2nd try: Add loose option for es2015-parameters transformation (#5943)
* Import changes to parameters package from previous branch

* Refactor plugin option access via state
2017-07-12 17:36:44 -04:00

20 lines
322 B
JavaScript

function required(msg) {
throw new Error(msg);
}
function sum(
{ arr = required('arr is required') } = { arr: arr = [] },
length = arr.length
) {
let i = 0;
let acc = 0;
for (let item of arr) {
if (i >= length) return acc;
acc += item;
i++;
}
return acc;
}
assert.equal(sum({arr:[1,2]}), 3);