{"id":19803,"date":"2020-11-17T22:33:21","date_gmt":"2020-11-18T06:33:21","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19803"},"modified":"2023-12-01T04:04:09","modified_gmt":"2023-12-01T12:04:09","slug":"javascript-bubble-sort","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/","title":{"rendered":"JavaScript Bubble Sort: A Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How to Write a JavaScript Bubble Sort<\/h2>\n\n\n\n<p>Do you have a list of values that you need to sort? The bubble sort could be for you. Bubble sorts compare adjacent elements in a list and swap their positions if they are not in the correct order.<\/p>\n\n\n\n<p>In this guide, we\u2019re going to talk about what bubble sorts are and how they work. We\u2019ll walk through how to write a bubble sort in JavaScript so you can quickly get started with this sort.<\/p>\n\n\n\n<p>Let\u2019s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a JavaScript Bubble Sort?<\/h2>\n\n\n\n<p>A bubble sort, or a &#8220;sinking sort,&#8221; is a simple sorting algorithm that compares a pair of adjacent elements in a list. If an element is not in the right order, we swap the element with the one before. Otherwise, the element remains in the same place.<\/p>\n\n\n\n<p>The bubble sort got its name because it loops through a list and moves all the largest values to the end. Another way of thinking about this is that the largest values \u201cbubble up\u201d at the end of the list. Bubble sorts work in both ascending or descending order.<\/p>\n\n\n\n<p>There are two types of bubble sorts: regular and optimized.<\/p>\n\n\n\n<p>Regular bubble sorts make all possible comparisons irrespective of whether an array is sorted. Optimized bubble sorts stop executing after an iteration has finished if no swapping has occurred.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bubble Sort JavaScript Walkthrough<\/h2>\n\n\n\n<p>We\u2019ll begin by talking about how bubble sorts work, and then we will implement one in JavaScript. Consider the following list of items:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>9<\/td><td>3<\/td><td>2<\/td><td>11<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>To start our sort, we will compare the first and second numbers. If the first number is greater than the second number, we swap the items. Otherwise, the items stay in the same place.<\/p>\n\n\n\n<p>9 is greater than 3 so the positions of the first two elements swap:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td><strong>3<\/strong><\/td><td><strong>9<\/strong><\/td><td>12<\/td><td>2<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>This process continues until we compare every item in the list.<\/p>\n\n\n\n<p>9 is not greater than 12, so these items stay in the same place. 12 is greater than 2, so these items swap:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>3<\/td><td>9<\/td><td><strong>2<\/strong><\/td><td><strong>12<\/strong><\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>Our list is now starting to look more ordered. Our algorithm has iterated through the list once. It will continue to do so until we order every item. In the next iteration, our program makes the following comparisons:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Is 3 greater than 9? No, so nothing happens.<\/li><li>Is 9 greater than 2? Yes, so the items swap.<\/li><li>Is 9 greater than 12? No, so nothing happens.<\/li><\/ul>\n\n\n\n<p>After this iteration, our list looks like this:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>3<\/td><td>2<\/td><td>9<\/td><td>12<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>We\u2019re almost there. In the next iteration we swap the first two elements, which gives us a completely sorted list:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>2<\/td><td>3<\/td><td>9<\/td><td>12<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>We did it! We have sorted a list using a bubble sort. Now comes the tricky part: implementing this algorithm in JavaScript.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Write a Bubble Sort in JavaScript<\/h2>\n\n\n\n<p>We can write a bubble sort algorithm in JavaScript. We\u2019ll create two bubble sorts: a regular bubble sort and an optimized one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Regular Bubble Sort<\/h3>\n\n\n\n<p>Let\u2019s start by defining a <a href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/\">JavaScript function<\/a> that conducts our bubble sort:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function sortItems(array) {\n\tfor (let i = 0; i &lt; array.length; i++) {\n\t\tfor (let j = 0; j &lt; array.length; j++) {\n\t\t\tif (array[j] &gt; array[j + 1]) {\n\t\t\t\tlet temp = array[j];\n\t\t\t\tarray[j] = array[j + 1];\n\t\t\t\tarray[j + 1] = temp;\n\t\t\t}\n\t\t}\n\t}\n\treturn array;\n}<\/pre><\/div>\n\n\n\n<p>This function takes in an array of numbers and sorts it using the bubble sort algorithm. To start, the algorithm creates a <a href=\"https:\/\/careerkarma.com\/blog\/javascript-for-loop\/\">for loop<\/a> which iterates through each item in the list.<\/p>\n\n\n\n<p>Our code uses the array length attribute to calculate the length of the list. Then, we declare another for loop. This for loop makes comparisons between each element in the list.<\/p>\n\n\n\n<p>For each iteration of our inner loop, our program executes an if statement. This <a href=\"https:\/\/careerkarma.com\/blog\/javascript-if-else\/\">JavaScript if statement<\/a> checks if the number on the left of a comparison is greater than the number on the right. If it is, our program swaps the numbers. Otherwise, nothing happens.<\/p>\n\n\n\n<p>We return the array to the main program after sorting it. Let\u2019s call our function and give it an example array:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var numbersToSort = [9, 3, 2, 11];\nvar sortedList = sortItems(numbersToSort);\nconsole.log(sortedList);<\/pre><\/div>\n\n\n\n<p>We have declared a <a href=\"https:\/\/careerkarma.com\/blog\/javascript-variables\/\">JavaScript variable<\/a> called <em>numbersToSort<\/em> which contains the numbers we want to sort. We have then called our <em>sortItems()<\/em> method and passed this variable as a parameter. This sorts our list. We print the newly-sorted list to the <a href=\"https:\/\/careerkarma.com\/blog\/javascript-console\/\">browser JavaScript console<\/a>: [2, 3, 9, 11].<\/p>\n\n\n\n<p>This code sorts our list in ascending order. We can change this behavior by replacing the \u201cgreater than\u201d sign in our \u201cif\u201d statement with a \u201cless than\u201d sign:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>if (array[j] &lt; array[j + 1]) {<\/pre><\/div>\n\n\n\n<p>We\u2019re almost done! Let\u2019s make our code more efficient by implementing a bubble sort with a swapped variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Optimized Bubble Sort<\/h3>\n\n\n\n<p>Optimized bubble sorts introduce a new variable. This variable keeps track of whether a swap occurs. The sort will stop if no swaps have occurred.<\/p>\n\n\n\n<p>To make our bubble sort more efficient, we will replace our outer for loop with a while loop:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function sortItems(array) {\n\tlet swapped = true;\n\tdo {\n\t\tswapped = false;\n\t\tfor (let j = 0; j &lt; array.length; j++) {\n\t\t\tif (array[j] &gt; array[j + 1]) {\n\t\t\t\tlet temp = array[j];\n\t\t\t\tarray[j] = array[j + 1];\n\t\t\t\tarray[j + 1] = temp;\n\t\t\t\tswapped = true;\n\t\t\t}\n\t\t}\n\t} while (swapped);\n\treturn array;\n}<\/pre><\/div>\n\n\n\n<p>The while loop will execute until \u201cswapped\u201d is equal to false. By default, the value of \u201cswapped\u201d is true. In each iteration of our list, we set the value of \u201cswapped\u201d false. If a swap occurs, the value of \u201cswapped\u201d returns to true.<\/p>\n\n\n\n<p>This allows us to keep track of whether a swap was made in an iteration. If no swap was made, it means our list is sorted. If this is the case, we can stop our bubble sort.<\/p>\n\n\n\n<p>Let\u2019s try to use this bubble sort:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var numbersToSort = [9, 3, 2, 11];\nvar sortedList = sortItems(numbersToSort);\nconsole.log(sortedList);<\/pre><\/div>\n\n\n\n<p>Our code returns: [2, 3, 9, 11]. Our list is sorted. This algorithm is more efficient because it does not perform any unnecessary comparisons. As soon as the list is sorted, the algorithm stops running.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Bubble sorts are a simple way to sort a list. They compare adjacent items in a list and swap them if they are not in the right order.<\/p>\n\n\n\n<p>There are more efficient sorts available such as an insertion sort or a merge sort. These sorts are more advanced. Bubble sorts are usually the best way to start learning about sorting algorithms.<\/p>\n\n\n\n<p>To learn more about coding in JavaScript, read our <a href=\"https:\/\/careerkarma.com\/blog\/how-to-learn-javascript\/\">How to Learn JavaScript guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"How to Write a JavaScript Bubble Sort Do you have a list of values that you need to sort? The bubble sort could be for you. Bubble sorts compare adjacent elements in a list and swap their positions if they are not in the correct order. In this guide, we\u2019re going to talk about what&hellip;","protected":false},"author":240,"featured_media":19804,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-19803","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript Bubble Sort: : A Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"A bubble sort compares adjacent elements in a list and moves them if they are not in the right order. On Career Karma, learn how to write a JavaScript bubble sort.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Bubble Sort: A Guide\" \/>\n<meta property=\"og:description\" content=\"A bubble sort compares adjacent elements in a list and moves them if they are not in the right order. On Career Karma, learn how to write a JavaScript bubble sort.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-18T06:33:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:04:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"JavaScript Bubble Sort: A Guide\",\"datePublished\":\"2020-11-18T06:33:21+00:00\",\"dateModified\":\"2023-12-01T12:04:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/\"},\"wordCount\":960,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/\",\"name\":\"JavaScript Bubble Sort: : A Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg\",\"datePublished\":\"2020-11-18T06:33:21+00:00\",\"dateModified\":\"2023-12-01T12:04:09+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"A bubble sort compares adjacent elements in a list and moves them if they are not in the right order. On Career Karma, learn how to write a JavaScript bubble sort.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-bubble-sort\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Bubble Sort: A Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript Bubble Sort: : A Step-By-Step Guide | Career Karma","description":"A bubble sort compares adjacent elements in a list and moves them if they are not in the right order. On Career Karma, learn how to write a JavaScript bubble sort.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Bubble Sort: A Guide","og_description":"A bubble sort compares adjacent elements in a list and moves them if they are not in the right order. On Career Karma, learn how to write a JavaScript bubble sort.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-11-18T06:33:21+00:00","article_modified_time":"2023-12-01T12:04:09+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"JavaScript Bubble Sort: A Guide","datePublished":"2020-11-18T06:33:21+00:00","dateModified":"2023-12-01T12:04:09+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/"},"wordCount":960,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/","url":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/","name":"JavaScript Bubble Sort: : A Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg","datePublished":"2020-11-18T06:33:21+00:00","dateModified":"2023-12-01T12:04:09+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"A bubble sort compares adjacent elements in a list and moves them if they are not in the right order. On Career Karma, learn how to write a JavaScript bubble sort.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/filiberto-santillan-1HCb2gPk3ik-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-bubble-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Bubble Sort: A Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19803"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19803\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/19804"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}