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

Just pulling the ol’ 1,2,3,4,5,6,7,8,9….y’know the rest
Now I’m thinking of “Take on Me” by A-ha.
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[2]) {
let b = piece[2]
let a = piece[1]
piece[2] = el
piece[1] = b
piece[0] = a
return
}
if(el > piece[1]) {
let a = piece[1]
piece[1] = el
piece[0] = a
return
}
if(el > piece[0]) {
piece[0] = 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)
We’re literally doing this to the ‘array’ argument.
doTheHustle(piece)
for( idx in array) {
let el = array[idx]
goldilocks(el, piece)
}
return piece
I don’t know what’s up with me and why I’m invoking fucking disco. *shrugs*
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[2]) {
let b = piece[2]
let a = piece[1]
piece[2] = el
piece[1] = b
piece[0] = a
return
}
if(el > piece[1]) {
let a = piece[1]
piece[1] = el
piece[0] = a
return
}
if(el > piece[0]) {
piece[0] = el
return
}
}
doTheHustle(piece)
  • We create a variable b to contain piece[2]
  • We create a variable a to contain piece[1]
  • We set piece[2] to equal el
  • We set piece[1] to equal b
  • We set piece[0] to equal a
  • Then we return
if(el > piece[2]) {
let b = piece[2]
let a = piece[1]
piece[2] = el
piece[1] = b
piece[0] = a
return
}
  • We create variable a to equal piece[1]
  • We set piece[1] to equal el
  • We set piece[0] to equal a
  • Then we return
if(el > piece[1]) {
let a = piece[1]
piece[1] = el
piece[0] = a
return
}
  • We set piece[0] to equal el
  • Then we return
if(el > piece[0]) {
piece[0] = el
return
}
to be clear, not a WAP…totally different content, go check out my non-existent OnlyFans for that XD

--

--

--

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

My first project at Flatiron School with CLI

What Are No Code Solutions?

Buzarnescu — Bolsova Zadoinov [LiVeStReaM]

Online live stream search engine

#DjangoTip: Select & Prefetch Related

Kubernetes Rant: Do Autoscalers make Business sense?

Understanding Billing in Google Cloud Storage

Most Important Java Developer Skills

How to Implement MVC Architecture in Java?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Rosales

Adrian Rosales

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)

More from Medium

THE KEY BENEFITS OF WORKING FROM THE OFFICE

11:59PM, End of Youth by Althea M. Sim

On Plato’s ‘Euthyphro’​ — A Dilemma

Improve L’Oreal’s Digital Experience with Ada