Step 3
After iterating through all the other elements, push the next variable onto the stack.

Step 4
When the loop in step 2 is done, pop all the elements from stack and set -1 as the next greater element for them.
xxxxxxxxxx17
var assert = require('assert');function nextLargerNumber(nums) { // implement this function return nums;}try { assert.deepEqual(nextLargerNumber([3, 1, 3, 4]), [4, 3, 4, -1]); console.log( 'PASSED: assert.deepEqual(nextLargerNumber([3, 1, 3, 4]), [4, 3, 4, -1])' );} catch (err) { console.log(err);}OUTPUT
Results will appear here.