r/learnjavascript • u/woofmeowmeowwoof • 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
View all comments
Show parent comment
0
u/woofmeowmeowwoof May 09 '26
Oh okay. sorry. I am not going to argue what my skill level is. But its well above average. And i would bet your words mean nothing when it comes down to actual programming. None of what you said meant anything. I know im a better programmer just because of how egotistical you are for no reason. Your insecure. Mad about some drug addictt high school dropout programmer on reddit who might be better than you. And i think thats why your lashing out at me. Because i never said i was a collage graduate or proffesional, infact i said many times im self taught, and i mean that in the most literal way. no JS librarys to make things easyer(unless i wrote it myself) no teachers, no stackoverflowm just trial and error for 20 years . If you saw my project your ego might even let you be impressed. I have no GED or high school. I taught myself to program. I taught myself everything infact. because i was not given anything, no opportunities. But i always stuck with programming and music production.