JSFiddle - React, Tailwind, and code Playground

by SLonoed

JavaScript

function Playlist() {
    this.current = 0;
    this.list = Array.prototype.slice.call(arguments);;
};

Playlist.prototype.prev = function() {
    if (this.current-1 < 0) {
        return null;
    }
    return this.list[--this.current];
};
Playlist.prototype.next = function() {
    if (this.current+1 >= this.list.length) { // length is index + 1
        return null;
    }
    return this.list[++this.current];
};
Playlist.prototype.getCurrent = function() {
    return this.current;
};

var newPlaylist = new Playlist(2,3,5,10/* those are my ids */);
console.log(newPlaylist)