You are given an iterator object with two methods, hasNext() and next(). Wrap it in a PeekingIterator that also supports peek(), which returns the next value without consuming it.
new PeekingIterator(iterator)peek() - the next value; calling it again returns the same value. Throw an Error if there is nonenext() - the next value, consuming it. Throw an Error if there is nonehasNext() - whether a value remains, taking a peeked value into account- Every value must be pulled from the wrapped iterator exactly once, and the constructor must not pull any
- Values may be any value, including
0, false, null and undefined