Why A and B are equal after sort()?

exebook
function randOrd() {
    return (Math.round(Math.random()) - 0.5)
}

A = [0,1,2,3,4,5,6,7]
var B = A.sort(randOrd)
console.log('A=',A)
console.log('B=',B)

output:

a= [ 3, 4, 0, 1, 6, 2, 5, 7 ]
b= [ 3, 4, 0, 1, 6, 2, 5, 7 ]

I expected a to be the original array and b to be sorted. But they are both equal (sorted), why?

chsh

Because the Array.sort() method sorts in-place and then returns the array.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why (A - B) .^ 2 is not equal to (B - A) .^ 2 in MATLAB?

From Dev

Ruby - Why does sort reorder equal elements

From Dev

Why are the outputs of `sort`, `sort k 1`, `sort k 1,1` equal?

From Dev

In the theory of computation, why are regular expressions (ab)* and a*b* not equal?

From Dev

Vlisp autocad: condition (> a b) is true even when a is equal b. Why?

From Dev

Vlisp autocad: condition (> a b) is true even when a is equal b. Why?

From Dev

Why 'sort{$a-$b}(list of floats)' doesn't work in Perl?

From Dev

Wellsortedness error ... not of sort equal

From Dev

Why does points.sort(function(a, b){return a-b}); return -1, 0 or 1?

From Dev

Javascript: Why is b1 considered undefined when o1 has a value and is equal to b1

From Dev

Why checkout -b does work only after second attempt?

From Dev

Why does `a` keeps the ownership after `let b = &*&a;` in Rust?

From Dev

Why is b' ' included in the excel file after web scraping?

From Dev

File is not sort after sort

From Dev

Sort list B by the sort of list A?

From Dev

Sort list B by the sort of list A?

From Dev

TreeMap sort is not working on equal values

From Dev

TreeMap sort is not working on equal values

From Dev

Extract after equal sign

From Dev

Is P(A, B) probability equal to P(A intersection B)?

From Dev

How to make add(a)(b) equal to a+b?

From Dev

Why does the value of "i" not change after executing "boolean t = true,b; b = (t || ((i++) == 0))"

From Java

Why null is not equal to null?

From Dev

Why are these two strings not equal?

From Dev

Why are the values of an OrderedDict not equal?

From Dev

Why these two are not equal?

From Dev

Why is !== "" is not equal to !== null

From Dev

Why is this expression equal?

From Dev

Why this arithmetic expression is not equal?

Related Related

  1. 1

    Why (A - B) .^ 2 is not equal to (B - A) .^ 2 in MATLAB?

  2. 2

    Ruby - Why does sort reorder equal elements

  3. 3

    Why are the outputs of `sort`, `sort k 1`, `sort k 1,1` equal?

  4. 4

    In the theory of computation, why are regular expressions (ab)* and a*b* not equal?

  5. 5

    Vlisp autocad: condition (> a b) is true even when a is equal b. Why?

  6. 6

    Vlisp autocad: condition (> a b) is true even when a is equal b. Why?

  7. 7

    Why 'sort{$a-$b}(list of floats)' doesn't work in Perl?

  8. 8

    Wellsortedness error ... not of sort equal

  9. 9

    Why does points.sort(function(a, b){return a-b}); return -1, 0 or 1?

  10. 10

    Javascript: Why is b1 considered undefined when o1 has a value and is equal to b1

  11. 11

    Why checkout -b does work only after second attempt?

  12. 12

    Why does `a` keeps the ownership after `let b = &*&a;` in Rust?

  13. 13

    Why is b' ' included in the excel file after web scraping?

  14. 14

    File is not sort after sort

  15. 15

    Sort list B by the sort of list A?

  16. 16

    Sort list B by the sort of list A?

  17. 17

    TreeMap sort is not working on equal values

  18. 18

    TreeMap sort is not working on equal values

  19. 19

    Extract after equal sign

  20. 20

    Is P(A, B) probability equal to P(A intersection B)?

  21. 21

    How to make add(a)(b) equal to a+b?

  22. 22

    Why does the value of "i" not change after executing "boolean t = true,b; b = (t || ((i++) == 0))"

  23. 23

    Why null is not equal to null?

  24. 24

    Why are these two strings not equal?

  25. 25

    Why are the values of an OrderedDict not equal?

  26. 26

    Why these two are not equal?

  27. 27

    Why is !== "" is not equal to !== null

  28. 28

    Why is this expression equal?

  29. 29

    Why this arithmetic expression is not equal?

HotTag

Archive