DEV Community

Cover image for Bubble Sort...in PURE CSS? [No JS] 😱

Bubble Sort...in PURE CSS? [No JS] 😱

GrahamTheDev on October 14, 2023

Imagine you are in an interview and you get asked "can you implement bubble sort"...and you answer the interviewer "sure, do you want that in JavaS...
Collapse
 
savvasstephnds profile image
Savvas Stephanides β€’

Bogosort next πŸ”₯

Collapse
 
zippcodder profile image
Deon Rich β€’

Canvas of babel with pure CSS πŸ˜‚

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

Haha, that scares even me! πŸ€£πŸ’—

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

Haha, I might actually do it. Although I may run into a limitation on the number of iterations etc.

Fun idea though! πŸ€£πŸ’—

Collapse
 
savvasstephnds profile image
Savvas Stephanides β€’

Or, if you're lucky enough, it might all get sorted in the first try. Literally the only sorting algorithm that has the potential to do so πŸ˜…πŸ˜…πŸ˜…

Thread Thread
 
grahamthedev profile image
GrahamTheDev β€’

Anywhere from O(1) to O(infinity) πŸ€£πŸ’—

Thread Thread
 
tanzimhossain2 profile image
Tanzim Hossain β€’

😁

Collapse
 
aminmansuri profile image
hidden_dude β€’

You sir are an evil genius..

Next up we expect to see your implementation of Doom in CSS.

Collapse
 
link2twenty profile image
Andrew Bone β€’

πŸ˜… if this was a valid reaction I'd have used it rather than heart.

There is a proposal for css var arrays (with CSS random too) so you might have to revisit this someday πŸ˜‰

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

Yeah that would probably make this 200 times easier and actually performant...but then it wouldn't be fun anymore! πŸ€£πŸ’—

Collapse
 
tanzimhossain2 profile image
Tanzim Hossain β€’

What about the time complexity for this?

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

O(n2) it is just bubble sort! πŸ€£πŸ’—

Collapse
 
tanzimhossain2 profile image
Tanzim Hossain β€’

πŸ‘Œβ€οΈ

Collapse
 
maxfindel profile image
Max F. Findel β€’

This is amazing 🀯 I'm impressed that you didn't mess up that very copy&paste-intensive code (if you did, I bet it was hell to debug) πŸ˜†

Collapse
 
tylim88 profile image
Acid Coder β€’

No wayπŸ’€

Collapse
 
mangor1no profile image
Mangor1no β€’

aint no way bruh...

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

Waaaay doood! πŸ€£πŸ’—

Collapse
 
commonsenseal profile image
Albert Wiersch β€’

Wow... that is crazy but also impressive, and all that CSS even passes CSS HTML Validator with no errors!

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

My CSS is always valid...even the stuff that isn't useful like this! πŸ€£πŸ’—

Collapse
 
zippcodder profile image
Deon Rich β€’

Wow thats insane!! Fascinating post!! You can definitley do some cool stuff with CSS if you know what you're doing!

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

Yeah, but at the same time, it is far less stressful to do it in a proper language! πŸ€£πŸ’—

Collapse
 
loremimpsu profile image
Lorem Impsu β€’

ow congrats, great post!

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

πŸ™πŸΌπŸ’—

Collapse
 
grahamthedev profile image
GrahamTheDev β€’

Ooohhh, we are number 9 in the series!

Number 10 should be fun...Conway's game of life...in pure HTML! πŸ€£πŸ’—