0.5.0 • Published 6 years ago
listr.js v0.5.0
listr.js
This library include a simple list
Methods
/**
* Initialize the list
*
* @param {Array|null} array
* @returns {Listr|undefined}
*/
initialize(array);
/**
* Check if the list is empty
*
* @returns {boolean}
*/
isEmpty();
/**
* Get the firts element of the list
*
* @returns {Object|undefined}
*/
head();
/**
* Get all elements of the list except the head
*
* @returns {Listr}
*/
tail();
/**
* Push an element at the end of the list
*
* @param {Object} element
* @returns {Listr|undefined}
*/
append(element);
/**
* Push an element at the beginning of the list
*
* @param {Object} element
* @returns {Listr|undefined}
*/
prepend(element);
/**
* Get list length
*
* @returns {number}
*/
length();
/**
* Delete all objects
*
* @returns {boolean}
*/
clear();
/**
* Get list as array
*
* @returns {Array}
*/
toArray();
/**
* Get list as string
*
* @returns {String}
*/
toString();
Example
const { Listr } = require('./listr');
let listr = new Listr();
listr.append(1);
listr.append(2);
listr.append(3);
listr.append(4);
listr.append(5);
listr.prepend(6);
listr.head(); // 1
listr.tail().toString(); // 2,3,4,5,6
listr.isEmpty(); // false
listr.length(); // 6
listr.toArray(); // [1, 2, 3, 4, 5, 6]
list.toArray();
for (let item of listr) {
item;
}