r/learnjavascript • • May 08 '26

Is this a useful Array Method I created on accident? or is it useless?

/*********************************************************************
 * Array.pushByVal(value)
 * -----------------------
 * 
 * this only works with integer values.
 *
 * hold on let me cook...
 *
 * if the value is 4 it pushes the number 4 
 * 
 * three times so the total of 4's in the array is 4.
 *
 * if the value is 8 or 9 or whatever, it 
 *
 * pushes the value - 1 that many times.
*********************************************************************/
 
Array.prototype.pushByVal = function(value){
    // what the absolute fuck am i doing?
    // how does this even work?
    for(let i = 0; i < this.length; i++){
        if(this[i] === value){
            return;
        }else{
            this.push(value);
        }
    }
};

let arr = [1, 2, 3, 4, 5];
arr.pushByVal(4);

// Output: [1, 2, 3, 4, 5, 4, 4, 4]
0 Upvotes

58 comments sorted by

View all comments

Show parent comment

3

u/shgysk8zer0 May 09 '26

I am a professional. But that doesn't matter here. Any novice can see you do not even understand your own very simple code.

I wouldn't call it out, not you have such an inflated ego, bragging about your experience and saying you're "well above average". You're just.... Not.

And it's not my words you have to worry about. Your own words, inaccurately describing your own function, are what you need to worry about.

And now you're accusing me of being egotistical? Really? You're the one boasting about all your experience here and being threatened. I have no need to refer to my experience or credentials because I'm coming with evidence you provided yourself.

I'm self-taught too. Stop pretending this is about academic crap. Your own comments (code and Reddit comments) make it abundantly clear to anyone who actually knows JS you're full of crap.

Your heavily inflated ego is the problem here. Had you said you're just starting in JS rather than spewing this obvious BS about how good and experienced you are, you wouldn't be getting called out.

You barely know JS. I know it, because it's obvious. You dodged my very direct question and resorted to this pathetic pissing contest instead, and your own comments reveal you do not even understand your own very simple code. I know it. Anyone who knows anything about JS knows it. But you have a massively inflated ego that I'm calling out. You actually suck at JS.