Click here to Skip to main content
15,946,988 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to sort arrays with object functions but I can't make it.

How can I list array size like this:
<pre>function bubbleSort(Length = 5){
            if (Length > 0)
                return bubbleSort(Length - 1);

What I have tried:


<pre><pre>Object.defineProperty(Array.prototype, "bubbleSort", {
    value: function bubbleSort(){
        var Length = this.length;

        if (Length > 0)
            this.length = Length - 1;
            return bubbleSort();
Updated 17-Apr-21 7:30am

1 solution

Why on earth would you even try to write a recursive bubble sort function? It's clearly an iterative algorithm!

Start here: Bubble sort - Wikipedia[^] and start again with an iterative solution.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900