Step 2/3 Iterate through the rest of the elements in a for-loop.
- Mark the iterated on/current element as the nextelement.
- If stack is not empty, compare topelement of the stack withnext.
- If nextis greater than the top element,popthe element from the stack. What this means is that we've determinednextis the next greater element for the popped number.
- While the popped element is smaller than next, keep popping off the top of the stack. As the logic follows,nextbecomes the next greater element for all the popped elements.

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.