Opening your workspace…
Workspace/Coding room
Opening your workspace…
Jack has reached the end of the measuring rope. The beanstalk, according to the giant shouting down from somewhere above the clouds, goes on quite a bit farther. Jack wants tomorrow's height so he can bring enough rope to measure it in one trip.
His notebook gives the height in feet at the same time each day. Make a second row by subtracting each height from the next. Keep taking differences until all numbers in a row are the same. Extend that constant row by one number. Then work upward: each new entry equals the last value in its row plus the new value directly below. Return the next height.
[2,5,10,17]Output26The differences are 3, 5, 7, so the next difference is 9. Adding it to 17 gives 26.
[1,4,9,16,25]Output36The first differences are 3, 5, 7, 9; their differences are all 2. Continue with first difference 11, giving 36.
The next height is the sum of the last entries on the successive difference rows.
function solve(heights) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.