Tag: bubble sort java

JavaScript implicit coercion of empty arrays

JavaScript implicit coercion of empty arrays example: [] == ![] //toBoolean [1] [] == !true [] == false //loose equality round one [2] //toPrimitive([]) [3] "" == false //loose equality round two //toBoolean("") [4] false === false true explanations: 1) First there is operator precedence so ! evaluates before == Negating something calls the internal toBoolean method onto that "something" first. … Continue reading JavaScript implicit coercion of empty arrays

Advertisements

bubble sort scala

/** blue sort*/ def Bluesort(array : Array[Int]): Array[Int] = { var flag = false for(i<- 0 until array.length -1) if(array(i+1) > array(i)){ //tang dan,giam dan > val tmp = array(i) array(i) = array(i+1) array(i+1) = tmp flag = true } // Repeat until we don't have anymore swaps if(flag) Bluesort(array) else array } def main(args: … Continue reading bubble sort scala