Arrays Example
Arrays and Functions: Example
funct ion b ubble_sort ( array ) { ... }
array = [20 ,4 ,3 ,9 ,6 ,8 ,5 ,10]
cons ole . log (" array before sorti ng " +
array . join (" , "))
sorted = bubble _ s o rt ( array . slice (0)) // slice c reates copy
cons ole . log (" array after so rting of copy " +
array . join (" , "))
sorted = bubble _ s o rt ( array )
cons ole . log (" array after so rting of itself " +
array . join (" , "))
cons ole . log (" sorted array " +
sorted . join (" , "))
array be fore sorting 20 , 4, 3 , 9, 6 , 8 , 5 , 10
array after sortin g of copy 20 , 4, 3, 9, 6, 8 , 5 , 10
array after sortin g of itse lf 3, 4, 5 , 6 , 8 , 9, 10, 20
sorted array 3, 4, 5, 6, 8 , 9 , 10 , 20
COMP519 Web Programming Lecture 14 Slide L14 – 10