The Partitioner
Medium+20 XP
Mission Briefing
The supply pod contains a massive array of resources, but the engineers strictly need the very first two items immediately! You must extract them using the cleanest code possible.
The Concept: Destructuring
Destructuring is an incredibly powerful ES6+ syntax that allows you to instantly unpack values from arrays (or properties from objects) into distinct variables!
Example: const [first, second] = [10, 20];
The Objective
Your function receives an array of numbers nums.
- Unpack the first two elements of
numsinto variablesaandbusing destructuring syntax. - Return their accumulated sum.
01EXAMPLE 1
Input
nums = [10, 20, 30]Output
30Constraints
- Use array destructuring [a, b] = nums.
CoreES6+
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
nums[10,20,30]
Expected Output
30
Click RUN to test your solution