Repository navigation
feat: add typed, pure library API and fix data-structure bugs - #5
Open
Sakibpedia wants to merge 1 commit into
Open
Sakibpedia wants to merge 1 commit into
Sakibpedia wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A proposal to change the foundation
AlgoDS.js currently teaches algorithms as standalone folders whose
index.jsprints a demo. That is great for learning, but it means the code is not usable as a library: there is no package entry point despite"main": "index.js", no types, functions assume valid input, and several sort/chunk helpers mutate the caller's array.This PR adds a second, additive foundation: AlgoDS as a pure, typed, importable library. The lesson folders are untouched. Nothing is removed.
What is added
index.js— a real public API with four namespaces:strings,arrays,math,patterns, plusdataStructuresclasses. All functions return values, validate arguments, and never mutate inputs (sorts/chunk copy their arrays first).index.d.ts— full TypeScript declarations for the whole API.tests/library.test.js— 41 tests using Node's built-in test runner, so the suite runs with zero installed dependencies:node --test tests/library.test.js.npm run test:libraryscript,types,exports,filesmetadata, and corrected repository/bugs/homepage URLs (they pointed to the oldAlgorithm.jsname).Real bugs found by the new suite
Building a tested API exposed defects in the original implementations. They are fixed here, with regression tests:
stack/stack.js,qFromStack/stack.jspeek()returneddata[0]whilepop()removes from the endstackFromQ/stack.jspeek()readthis.data(never set) →TypeErrorpeek/popstackFromQ/queue.jsqFromStack/queue.jsremove, returning the newest instead of the oldests2is emptylinkedList/fromLast.jsfromLast(list, 2)returned the 3rd node from the endVerification
tsc --noEmit --strict --skipLibCheck index.d.tspasses.node fibonacci/index.js,node bubbleSort/index.js) still run unchanged.This is intentionally a proposal: if you prefer a different namespace layout or want the lesson code frozen completely, I can split the bug fixes into a separate PR and reshape the API.