locutus
Version:
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
24 lines (23 loc) • 831 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.reset = reset;
const _arrayPointers_ts_1 = require("../_helpers/_arrayPointers.js");
function reset(arr) {
// discuss at: https://locutus.io/php/reset/
// original by: Kevin van Zonneveld (https://kvz.io)
// bugfixed by: Legaev Andrey
// revised by: Brett Zamir (https://brett-zamir.me)
// note 1: Uses global: locutus to store the array pointer
// example 1: reset({0: 'Kevin', 1: 'van', 2: 'Zonneveld'})
// returns 1: 'Kevin'
const state = (0, _arrayPointers_ts_1.getPointerState)(arr, true);
if (!state) {
return false;
}
const entry = (0, _arrayPointers_ts_1.getEntryAtCursor)(arr, 0);
if (!entry) {
return false;
}
state.setCursor(0);
return entry[1];
}