mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
* Support primitive and function property descriptors * Dispatch literal bracket calls to native class methods * Handle numeric class method keys in bracket calls * Call function values returned by class accessors * Expand native object and array semantics * Keep new corpus fixtures aligned with compiler gates * Lower Object.isFrozen arguments once
19 lines
867 B
JavaScript
19 lines
867 B
JavaScript
const values = JSON.parse('[1,2,3,4]');
|
|
console.log(values.reduce((a, b) => a + b));
|
|
console.log(values.reduceRight((a, b) => a - b));
|
|
console.log(values.reduce((a, b) => a + b, 10));
|
|
console.log(values.findLast(x => x < 4), values.findLastIndex(x => x < 4));
|
|
console.log(values.findLast(x => x > 9), values.findLastIndex(x => x > 9));
|
|
try { JSON.parse('[]').reduce((a, b) => a + b); } catch (error) { console.log(error.name); }
|
|
console.log(JSON.parse('[]').reduce((a, b) => a + b, 5));
|
|
console.log(JSON.parse('[7]').reduce((a, b) => a + b));
|
|
console.log(JSON.parse('[7]').reduceRight((a, b) => a + b));
|
|
const shrinking = JSON.parse('[1,2,3]');
|
|
const seen = [];
|
|
const found = shrinking.findLast((value, index) => {
|
|
seen.push(`${index}:${value}`);
|
|
if (index === 2) shrinking.length = 1;
|
|
return false;
|
|
});
|
|
console.log(found, seen.join(','), shrinking.join(','));
|