Deadline |
---|
20.02.2017 09:00 |
Your task is to implement Self organizing list data structure. Please read about Move to Front Method.
- Fork this repo
- Install nodejs (>= v6.2.0)
- open bash in this folder
npm install
- Implement class methods (fille
src/self-organized-list.js
, teststest/self-organized-list.spec.js
) - Commit your changes
- Push changes to github
- Submit your task to RS School Padawans
const sol = new SelfOrganizedList()
sol.insert(data)
Inserts data to the list;
sol.size()
Returns list length;
sol.at(index)
Returns data of the n-th element in the list;
sol.findNode(data)
Returns first founded Node that has provided data;
sol.toArray()
Returns array representation of the list;
sol.removeAt(index)
Remove n-th node from the list;
sol.moveToFront(node)
Moves node to the top of the list;
sol.reorganize(data)
Tries to find node with the data and move to front if data exist in the list; returns true
if exist and false
if not;
const sol = new SelfOrganizedList();
sol.insert('Game of gnomes');
sol.insert('Superficial');
sol.insert('Breaking good');
sol.size(); // 3
sol.at(1); // Superficial
sol.toArray(); // ['Game of gnomes', 'Superficial', 'Breaking good']
sol.reorganize('Breaking good'); // true, and reorganize list to 'Breaking good' -> 'Game of gnomes' -> 'Superficial'
sol.reorganize('Breaking bad'); // false, list the same
npm test
npm start
open http://localhost:8080 and hack in the browser console!