Click here to Skip to main content
15,881,172 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)
            {
                console.log(Length);
                return bubbleSort(Length - 1);
            }
        }


What I have tried:

HTML
console.log(Calendar.bubbleSort());

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

        if (Length > 0)
        {
            this.length = Length - 1;
            console.log(Length);
            return bubbleSort();
        }
    }
});
Posted
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
 
v2

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