1 < [6] how does this comparison compare in a JavaScript environment?

binary sorting method of arrays:
function quickSort (arr) {

            if (!Array.isArray(arr) || arr.length == 0) {
                return [];
            };
            var cIndex = Math.floor(arr.length / 2),
                c = arr.splice(cIndex,1),
                l = [],
                r = [];
            for (var i = 0; i < arr.length; iPP) {
                if (arr[i] < c) {
                    l.push(arr[i]);
                } else{
                    r.push(arr[i]);
                };
            };
            return quickSort(l).concat(c,quickSort(r));
        };
The comparison of arr [I] < c in

is actually similar to the question I asked. How does a number compare with an array?

Jul.17,2022

I don't understand what you want to ask. Arr [I] represents the element c in the subscript I of the convenience array. C represents the returned field deleted or added by arr


C is not an array


refer to https://www.cnblogs.com/Juphy...

1truefalse10
2
3null0.
4undefinedNaN
5:
     10
     20
     30
     4NaN
6valueOf()NaNtoString()
The elements of the

Array.valueOf array are converted to strings separated by commas and concatenated together. Its operation is the same as the Array.toString and Array.join methods.

[6] = > '6' = > 6
so 1 < [6] = true


https://developer.mozilla.org...
https://developer.mozilla.org...
compared to tutorials written by others, I recommend you to see mdn

Menu