Skip to content

Repository files navigation

js-trees

github action status

Зачем это нужно

Деревья на изменяемых узлах: узел знает своих детей и родителя, и его можно менять на месте. Нужна курсам, где разбирают обход дерева и рекурсию.

Парная к ней библиотека @hexlet/immutable-fs-trees решает ту же задачу неизменяемыми структурами: сравнение двух подходов и есть предмет изучения.

Install

npm install @hexlet/trees

Usage example

import Tree from '@hexlet/trees';

const tree = new Tree('/', 'root directory');
tree.getMeta(); // 'root directory'
const etcNode = tree.addChild('etc');
etcNode.getKey(); // 'etc'

tree.hasChild('etc'); // true
etcNode.getParent() === tree; // true

etcNode.hasChildren(); // false
tree.hasChildren(); // true

const libNode = etcNode.addChild('lib');
libNode === tree.getChild('lib'); // true
libNode === tree.getDeepChild(['etc', 'lib']); // true

etcNode.removeChild('lib'); // true
etcNode.hasChild('lib'); // false

For more information, see the Full Documentation

Hexlet Ltd. logo

This repository is created and maintained by the team and the community of Hexlet, an educational project. Read more about Hexlet.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages