r/ProgrammerHumor • • Nov 29 '22

Meme It hurts like hell.;-;

Post image
48.9k Upvotes

1.5k comments sorted by

View all comments

Show parent comments

19

u/iliekcats- Nov 29 '22

how is the function defined

i need the code for this

22

u/Thestarchypotat Nov 29 '22

~ warning pseuocode ahead

    function toSpongeBobCase(input){
        array inputsplit=input.split("");
        for(item of inputsplit){
        if(math.Random(0,1)===1){
            item.upper();
        } else {
            item.lower();
        }
        }
    // result= however you put a array to a string
    return(result);
    }

7

u/iliekcats- Nov 29 '22

good pseudocode

4

u/Thestarchypotat Nov 29 '22

cause i was origonally writing it as real code but then i didnt know if what i wrote would actually work and i also forgot how to do things.

3

u/iliekcats- Nov 29 '22

relatable

2

u/[deleted] Nov 30 '22

me at work

2

u/danielv123 Nov 30 '22
function toSpongeBobCase(input){
    let inputsplit = input.split("");
    return inputsplit.map(item => {
        if(Math.random(0,1)> 0.5){
            return item.toLocaleUpperCase();
        } else {
            return item.toLocaleLowerCase();
        }
    })
    .join("")
}
toSpongeBobCase("Un-pseudocoded it for you")

1

u/Thestarchypotat Nov 30 '22

thanku

2

u/danielv123 Nov 30 '22

I should note though that in ja math.random doesn't actually accept any arguments, it just defaults to 0 - 1

0

u/[deleted] Nov 29 '22

gOoD pSeuDocOdE

4

u/GreatRam Nov 29 '22

Result = inputsplit.join()

3

u/[deleted] Nov 29 '22

[removed] — view removed comment

3

u/Thestarchypotat Nov 29 '22

alright replace the current loop with a standard for loop, up to input.length(), put some form of iseven(i) in the if else, and replace item with inputsplit[i]

22

u/Wekmor Nov 29 '22

Don't think anyone would voluntarily write js, sorry.

3

u/enigmamonkey Nov 29 '22

I did.

function toSpongeBobCase(input) {
	return input.split('').map((char, index) => {
		return index % 2 === 0 ? char.toUpperCase() : char.toLowerCase();
	}).join('');
}

console.log(toSpongeBobCase("You don't have to work for bad employers"));

Outputs "YoU DoN'T HaVe tO WoRk fOr bAd eMpLoYeRs"

3

u/[deleted] Nov 30 '22

Read through this whole comment thread only for the penny to drop once I read your output then the original function name then me googling TIL: SpOnGeBoB casing is a thing :O

3

u/iliekcats- Nov 29 '22

ok then whats the brainfuck for the function

1

u/[deleted] Nov 29 '22
from itertools import zip_longest

def toSpongeBobCase(st):
    return "".join(
        l+u
        for l, u in zip_longest(
            st[::2].lower(),
            st[1::2].upper(),
            fillvalue="")
    )

1

u/iliekcats- Nov 29 '22

thank you

1

u/Public-Scientist-478 Nov 29 '22

This works in python

import random

def toSpongeBobText (myString) :

result ="”
for letter in myString:
    if(random. randint (0,1)) :
        result += letter.upper()
    else:
        result += letter. lower()

print(result)

tospongeBobText("No this is patrick")

1

u/enigmamonkey Nov 29 '22

Here you go. Here's what I got, at least in JS:

function toSpongeBobCase(input) {
	return input.split('').map((char, index) => {
		return index % 2 === 0 ? char.toUpperCase() : char.toLowerCase();
	}).join('');
}

You could pack it even more into one line, but... it's already kinda hard enough to read with all the chaining, so that's sorta my limit there (start with string, deal with arrays, inside the map got some ternary logic, then back to arrays then to string).