UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

26 lines (25 loc) 931 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.next = next; const _arrayPointers_ts_1 = require("../_helpers/_arrayPointers.js"); function next(arr) { // discuss at: https://locutus.io/php/next/ // parity verified: PHP 8.3 // original by: Brett Zamir (https://brett-zamir.me) // note 1: Uses global: locutus to store the array pointer // example 1: var $transport = ['foot', 'bike', 'car', 'plane'] // example 1: next($transport) // example 1: next($transport) // returns 1: 'car' const state = (0, _arrayPointers_ts_1.getPointerState)(arr, true); if (!state) { return false; } const nextCursor = state.cursor + 1; const entry = (0, _arrayPointers_ts_1.getEntryAtCursor)(arr, nextCursor); if (!entry) { return false; } state.setCursor(nextCursor); return entry[1]; }