# CoDEVIANT #27 — Goldilocks, Kit-Kat Bars, & the Three Integers

`function findThreeLargestNumbers(array) { let piece = array.splice(0,3)doTheHustle(piece)for( idx in array) {  let el = array[idx]  goldilocks(el, piece) }  return piece}function goldilocks(el, piece) {  doTheHustle(piece) if(el > piece) {  let b = piece  let a = piece  piece = el  piece = b  piece = a  return } if(el > piece) {  let a = piece  piece = el  piece = a  return } if(el > piece) {  piece = el  return }}function doTheHustle(piece) { for(let i = 0; i <= piece.length -1 ; i++) {  if(piece[i] > piece [i + 1]) {   let tmp = piece[i]   piece[i] = piece[i + 1]   piece[i +1] = tmp  } }}`
`function findThreeLargestNumbers(array) { let piece = array.splice(0,3) doTheHustle(piece) for( idx in array) {  let el = array[idx]  goldilocks(el, piece) }  return piece}`
`let piece = array.splice(0,3)`
`doTheHustle(piece)`
`for( idx in array) {  let el = array[idx]  goldilocks(el, piece) }`
`return piece`
`function doTheHustle(piece) { for(let i = 0; i <= piece.length - 1 ; i++) {  if(piece[i] > piece [i + 1]) {   let tmp = piece[i]   piece[i] = piece[i + 1]   piece[i + 1] = tmp  } }}`
`for(let i = 0; i <= piece.length - 1 ; i++) { ... }`
• Create a variable called tmp which holds the current value of piece[i]
• Set piece[i] to equal piece[i + 1]
• Set piece[i + 1] to equal whatever value is stored in tmp
`if(piece[i] > piece [i + 1]) {   let tmp = piece[i]   piece[i] = piece[i + 1]   piece[i + 1] = tmp}`
`function goldilocks(el, piece) { doTheHustle(piece)  if(el > piece) {  let b = piece  let a = piece  piece = el  piece = b  piece = a  return } if(el > piece) {  let a = piece  piece = el  piece = a  return } if(el > piece) {  piece = el  return }}`
`doTheHustle(piece)`
• We create a variable b to contain piece
• We create a variable a to contain piece
• We set piece to equal el
• We set piece to equal b
• We set piece to equal a
• Then we return
`if(el > piece) {  let b = piece  let a = piece  piece = el  piece = b  piece = a  return }`
• We create variable a to equal piece
• We set piece to equal el
• We set piece to equal a
• Then we return
`if(el > piece) {  let a = piece  piece = el  piece = a  return }`
• We set piece to equal el
• Then we return
`if(el > piece) {  piece = el  return }`

--

--