The Algorithms - JavaScript

JavaScript Repository of TheAlgorithms, which implements various algorithms and data structures in JavaScript.

JavaScript Banner

Gitpod ready-to-code Checks codecov Contributions Welcome standard.js Discord chat


These implementations are for demonstrative purposes only. Dedicated implementations of these algorithms and data structures are much better for performance and security reasons. We also do not provide any guarantee for api stability.


Before contributing to this repository, make sure to read our Contribution Guidelines. You can look at other TheAlgorithms Repositories or the issues with a "help wanted" label for inspiration regarding what to implement. Our maintainers will guide you through how to make your contribution properly if you make any mistakes. The names of the maintainers of this repository are listed in the CODEOWNERS file.

You can find a list of the algorithms currently in the repository in the directory. Explanations of many of the algorithms can be found in the wiki.


Thanks to all the contributors ❤️

TheAlgorithms/JavaScript

{
"props": {
"initialPayload": {
"allShortcutsEnabled": false,
"path": "/",
"repo": {
"id": 97086543,
"defaultBranch": "master",
"name": "JavaScript",
"ownerLogin": "TheAlgorithms",
"currentUserCanPush": false,
"isFork": false,
"isEmpty": false,
"createdAt": "2017-07-13T06:12:33.000Z",
"ownerAvatar": "https://avatars.githubusercontent.com/u/20487725?v=4",
"public": true,
"private": false,
"isOrgOwned": true
},
"currentUser": null,
"refInfo": {
"name": "master",
"listCacheKey": "v0:1698470626.0",
"canEdit": false,
"refType": "branch",
"currentOid": "fb0a99c15a39a222da960fc4ff0be12bdbae3517"
},
"tree": {
"items": [
{
"name": ".github",
"path": ".github",
"contentType": "directory"
},
{
"name": ".husky",
"path": ".husky",
"contentType": "directory"
},
{
"name": "Backtracking",
"path": "Backtracking",
"contentType": "directory"
},
{
"name": "Bit-Manipulation",
"path": "Bit-Manipulation",
"contentType": "directory"
},
{
"name": "Cache",
"path": "Cache",
"contentType": "directory"
},
{
"name": "Cellular-Automata",
"path": "Cellular-Automata",
"contentType": "directory"
},
{
"name": "Ciphers",
"path": "Ciphers",
"contentType": "directory"
},
{
"name": "Conversions",
"path": "Conversions",
"contentType": "directory"
},
{
"name": "Data-Structures",
"path": "Data-Structures",
"contentType": "directory"
},
{
"name": "Dynamic-Programming",
"path": "Dynamic-Programming",
"contentType": "directory"
},
{
"name": "Geometry",
"path": "Geometry",
"contentType": "directory"
},
{
"name": "Graphs",
"path": "Graphs",
"contentType": "directory"
},
{
"name": "Hashes",
"path": "Hashes",
"contentType": "directory"
},
{
"name": "Maths",
"path": "Maths",
"contentType": "directory"
},
{
"name": "Navigation",
"path": "Navigation",
"contentType": "directory"
},
{
"name": "Project-Euler",
"path": "Project-Euler",
"contentType": "directory"
},
{
"name": "Recursive",
"path": "Recursive",
"contentType": "directory"
},
{
"name": "Search",
"path": "Search",
"contentType": "directory"
},
{
"name": "Sorts",
"path": "Sorts",
"contentType": "directory"
},
{
"name": "String",
"path": "String",
"contentType": "directory"
},
{
"name": "Timing-Functions",
"path": "Timing-Functions",
"contentType": "directory"
},
{
"name": "Trees",
"path": "Trees",
"contentType": "directory"
},
{
"name": ".gitignore",
"path": ".gitignore",
"contentType": "file"
},
{
"name": ".gitpod.yml",
"path": ".gitpod.yml",
"contentType": "file"
},
{
"name": ".prettierignore",
"path": ".prettierignore",
"contentType": "file"
},
{
"name": ".prettierrc",
"path": ".prettierrc",
"contentType": "file"
},
{
"name": "CONTRIBUTING.md",
"path": "CONTRIBUTING.md",
"contentType": "file"
},
{
"name": "DIRECTORY.md",
"path": "DIRECTORY.md",
"contentType": "file"
},
{
"name": "LICENSE",
"path": "LICENSE",
"contentType": "file"
},
{
"name": "README.md",
"path": "README.md",
"contentType": "file"
},
{
"name": "package-lock.json",
"path": "package-lock.json",
"contentType": "file"
},
{
"name": "package.json",
"path": "package.json",
"contentType": "file"
},
{
"name": "vitest.config.ts",
"path": "vitest.config.ts",
"contentType": "file"
}
],
"templateDirectorySuggestionUrl": null,
"readme": null,
"totalCount": 33,
"showBranchInfobar": false
},
"fileTree": null,
"fileTreeProcessingTime": null,
"foldersToFetch": [],
"treeExpanded": false,
"symbolsExpanded": false,
"isOverview": true,
"overview": {
"banners": {
"shouldRecommendReadme": false,
"isPersonalRepo": false,
"showUseActionBanner": false,
"actionSlug": null,
"actionId": null,
"showProtectBranchBanner": false,
"recentlyTouchedDataChannel": null,
"publishBannersInfo": {
"dismissActionNoticePath": "/settings/dismiss-notice/publish_action_from_repo",
"releasePath": "/TheAlgorithms/JavaScript/releases/new?marketplace=true",
"showPublishActionBanner": false
},
"interactionLimitBanner": null,
"showInvitationBanner": false,
"inviterName": null
},
"codeButton": {
"contactPath": "/contact",
"isEnterprise": false,
"local": {
"protocolInfo": {
"httpAvailable": true,
"sshAvailable": null,
"httpUrl": "https://github.com/TheAlgorithms/JavaScript.git",
"showCloneWarning": null,
"sshUrl": null,
"sshCertificatesRequired": null,
"sshCertificatesAvailable": null,
"ghCliUrl": "gh repo clone TheAlgorithms/JavaScript",
"defaultProtocol": "http",
"newSshKeyUrl": "/settings/ssh/new",
"setProtocolPath": "/users/set_protocol"
},
"platformInfo": {
"cloneUrl": "https://desktop.github.com",
"showVisualStudioCloneButton": false,
"visualStudioCloneUrl": "https://windows.github.com",
"showXcodeCloneButton": false,
"xcodeCloneUrl": "https://developer.apple.com",
"zipballUrl": "/TheAlgorithms/JavaScript/archive/refs/heads/master.zip"
}
},
"newCodespacePath": "/codespaces/new?hide_repo_select=true&repo=97086543"
},
"popovers": {
"rename": null,
"renamedParentRepo": null
},
"commitCount": "1,807",
"overviewFiles": [
{
"displayName": "README.md",
"repoName": "JavaScript",
"refName": "master",
"path": "README.md",
"preferredFileType": "readme",
"tabName": "README",
"richText": "<article class=\"markdown-body entry-content container-lg\" itemprop=\"text\"><h1 tabindex=\"-1\" dir=\"auto\"><a id=\"user-content-the-algorithms---javascript\" class=\"anchor\" aria-hidden=\"true\" tabindex=\"-1\" href=\"#the-algorithms---javascript\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a>The Algorithms - JavaScript</h1>\n\n<p dir=\"auto\">JavaScript Repository of TheAlgorithms, which implements various algorithms and data structures in JavaScript.</p>\n<div align=\"center\" dir=\"auto\">\n<p dir=\"auto\"><a href=\"/TheAlgorithms/JavaScript/blob/master/DIRECTORY.md\"><img src=\"https://user-images.githubusercontent.com/68542775/167072911-dc31eac8-6885-4a05-9c25-279ecce22a79.png\" alt=\"JavaScript Banner\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\"><a href=\"https://gitpod.io/#https://github.com/TheAlgorithms/JavaScript\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/cfccaf0478b02ac3a1de428e0760e791b70e645273ed2dcbb32c08c8bc03b25b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f476974706f642d72656164792d2d746f2d2d636f64652d626c75653f6c6f676f3d676974706f64\" alt=\"Gitpod ready-to-code\" data-canonical-src=\"https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod\" style=\"max-width: 100%;\"></a>\n<a href=\"https://github.com/TheAlgorithms/JavaScript/actions\"><img src=\"https://camo.githubusercontent.com/b856c08b65f8bec5ed90973a63792649c4a55e6b27a47cea37c7ee487541df26/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f546865416c676f726974686d732f4a6176615363726970742f43692e796d6c3f6272616e63683d6d6173746572266c6162656c3d636865636b73\" alt=\"Checks\" data-canonical-src=\"https://img.shields.io/github/actions/workflow/status/TheAlgorithms/JavaScript/Ci.yml?branch=master&amp;label=checks\" style=\"max-width: 100%;\"></a>\n<a href=\"https://codecov.io/gh/TheAlgorithms/JavaScript\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/dbe353b2ec6868caef733cd212cb9849f5973ce2e073aba675776b3fd8142505/68747470733a2f2f636f6465636f762e696f2f67682f546865416c676f726974686d732f4a6176615363726970742f67726170682f62616467652e7376673f746f6b656e3d3856655a774c33314b5a\" alt=\"codecov\" data-canonical-src=\"https://codecov.io/gh/TheAlgorithms/JavaScript/graph/badge.svg?token=8VeZwL31KZ\" style=\"max-width: 100%;\"></a>\n<a href=\"/TheAlgorithms/JavaScript/blob/master/CONTRIBUTING.md\"><img src=\"https://camo.githubusercontent.com/a4f0538b5d79210125f97eb886145234b656b1d75c0250e7ebbefa6f3d1efcc5/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76312e7376673f6c6162656c3d436f6e747269627574696f6e73266d6573736167653d57656c636f6d6526636f6c6f723d303035396233\" alt=\"Contributions Welcome\" data-canonical-src=\"https://img.shields.io/static/v1.svg?label=Contributions&amp;message=Welcome&amp;color=0059b3\" style=\"max-width: 100%;\"></a>\n<a href=\"https://standardjs.com/\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/7d480602e05776a4e67a2a49aa7f0eb64680d6fb7d0dd49b33d9466f038d073e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d7374616e646172646a732d253233663364663439\" alt=\"standard.js\" data-canonical-src=\"https://img.shields.io/badge/code%20style-standardjs-%23f3df49\" style=\"max-width: 100%;\"></a>\n<a href=\"https://the-algorithms.com/discord/\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/ff45f0a17fa154a6b8277d9e639e0b8624a40c45d95728d9bc9623142f2c5922/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3830383034353932353535363638323738322e7376673f6c6f676f3d646973636f726426636f6c6f72423d373238394441\" alt=\"Discord chat\" data-canonical-src=\"https://img.shields.io/discord/808045925556682782.svg?logo=discord&amp;colorB=7289DA\" style=\"max-width: 100%;\"></a></p>\n</div>\n<hr>\n\n<h4 align=\"center\" tabindex=\"-1\" dir=\"auto\"><a id=\"user-content---these-implementations-are-for-demonstrative-purposes-only-dedicated-implementations-of-these-algorithms-and-data--structures-are-much-better-for-performance-and-security-reasons-we-also-do-not-provide-any-guarantee-for-api-stability\" class=\"anchor\" aria-hidden=\"true\" tabindex=\"-1\" href=\"#--these-implementations-are-for-demonstrative-purposes-only-dedicated-implementations-of-these-algorithms-and-data--structures-are-much-better-for-performance-and-security-reasons-we-also-do-not-provide-any-guarantee-for-api-stability\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a>\n These implementations are for demonstrative purposes only. Dedicated implementations of these algorithms and data\n structures are much better for performance and security reasons. We also do not provide any guarantee for api stability.\n</h4>\n<hr>\n\n<p dir=\"auto\">Before contributing to this repository, make sure to read our <a href=\"/TheAlgorithms/JavaScript/blob/master/CONTRIBUTING.md\">Contribution Guidelines</a>. You can look\nat other <a href=\"https://github.com/orgs/TheAlgorithms/repositories\">TheAlgorithms Repositories</a> or the <a href=\"https://github.com/TheAlgorithms/JavaScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22\">issues with a \"help wanted\" label</a> for\ninspiration regarding what to implement. Our maintainers will guide you through how to make your contribution properly\nif you make any mistakes. The names of the maintainers of this repository are listed in the\n<a href=\"/TheAlgorithms/JavaScript/blob/master/.github/CODEOWNERS\">CODEOWNERS file</a>.</p>\n<p dir=\"auto\">You can find a list of the algorithms currently in the repository in the <a href=\"/TheAlgorithms/JavaScript/blob/master/DIRECTORY.md\">directory</a>. Explanations of\nmany of the algorithms can be found in the <a href=\"https://github.com/TheAlgorithms/JavaScript/wiki\">wiki</a>.</p>\n<hr>\n\n\n\n<h2 tabindex=\"-1\" dir=\"auto\"><a id=\"user-content-thanks-to-all-the-contributors-️\" class=\"anchor\" aria-hidden=\"true\" tabindex=\"-1\" href=\"#thanks-to-all-the-contributors-️\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a>Thanks to all the contributors ❤️</h2>\n<a href=\"https://github.com/TheAlgorithms/JavaScript/graphs/contributors\">\n <img src=\"https://camo.githubusercontent.com/2411d6acd8b4222db4da4eb84b02305f71b701e6a8c8887e2a7ae2d93baff263/68747470733a2f2f636f6e747269622e726f636b732f696d6167653f7265706f3d546865416c676f726974686d732f4a617661536372697074\" data-canonical-src=\"https://contrib.rocks/image?repo=TheAlgorithms/JavaScript\" style=\"max-width: 100%;\">\n</a>\n</article>",
"loaded": true,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": [
{
"level": 1,
"text": "The Algorithms - JavaScript",
"anchor": "the-algorithms---javascript",
"htmlText": "The Algorithms - JavaScript"
},
{
"level": 4,
"text": "\n These implementations are for demonstrative purposes only. Dedicated implementations of these algorithms and data\n structures are much better for performance and security reasons. We also do not provide any guarantee for api stability.\n",
"anchor": "--these-implementations-are-for-demonstrative-purposes-only-dedicated-implementations-of-these-algorithms-and-data--structures-are-much-better-for-performance-and-security-reasons-we-also-do-not-provide-any-guarantee-for-api-stability",
"htmlText": "\n These implementations are for demonstrative purposes only. Dedicated implementations of these algorithms and data\n structures are much better for performance and security reasons. We also do not provide any guarantee for api stability.\n"
},
{
"level": 2,
"text": "Thanks to all the contributors ❤️",
"anchor": "thanks-to-all-the-contributors-️",
"htmlText": "Thanks to all the contributors ❤️"
}
],
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2FTheAlgorithms%2FJavaScript"
}
},
{
"displayName": "CODE_OF_CONDUCT.md",
"repoName": ".github",
"refName": "master",
"path": "CODE_OF_CONDUCT.md",
"preferredFileType": "code_of_conduct",
"tabName": "Code of conduct",
"richText": null,
"loaded": false,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": null,
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2FTheAlgorithms%2FJavaScript"
}
},
{
"displayName": "LICENSE",
"repoName": "JavaScript",
"refName": "master",
"path": "LICENSE",
"preferredFileType": "license",
"tabName": "GPL-3.0",
"richText": null,
"loaded": false,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": null,
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2FTheAlgorithms%2FJavaScript"
}
}
],
"overviewFilesProcessingTime": 22.171377
}
},
"appPayload": {
"helpUrl": "https://docs.github.com",
"findFileWorkerPath": "/assets-cdn/worker/find-file-worker-32bb159cc57c.js",
"findInFileWorkerPath": "/assets-cdn/worker/find-in-file-worker-c6704d501c10.js",
"githubDevUrl": null,
"enabled_features": {
"code_nav_ui_events": false,
"copilot_conversational_ux": false,
"copilot_conversational_ux_embedding_update": false,
"copilot_popover_file_editor_header": false,
"copilot_smell_icebreaker_ux": true,
"copilot_workspace": false,
"codeview_firefox_inert": true
}
}
}
}
{
"accept-ranges": "bytes",
"cache-control": "max-age=0, private, must-revalidate",
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'; base-uri 'self'; child-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com api.githubcopilot.com objects-origin.githubusercontent.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/",
"content-type": "text/html; charset=utf-8",
"date": "Mon, 26 Feb 2024 11:41:36 GMT",
"etag": "0cd9dfadbcadbfec58688ca165f10a4d",
"referrer-policy": "no-referrer-when-downgrade",
"server": "GitHub.com",
"set-cookie": "logged_in=no; Path=/; Domain=github.com; Expires=Wed, 26 Feb 2025 11:41:35 GMT; HttpOnly; Secure; SameSite=Lax",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"transfer-encoding": "chunked",
"vary": "X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, Accept-Encoding, Accept, X-Requested-With",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-request-id": "9B10:067D:1B68D0C:26DB670:65DC78EF",
"x-xss-protection": "0"
}