String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.slice(1);};
String.prototype.followCase=function(b){
	if(b==b.toUpperCase()){return this.toUpperCase();}
	if(b==b.toLowerCase()){return this.toLowerCase();}
	if(b==b.capitalize()){return this.capitalize();}
	return this;
};
String.prototype.atRemoveAdd=function(index,n,string){
	return this.substring(0,index)+string+this.substring(index+n,this.length);
};
String.prototype.matchIndex=function(re){
	var a=[];
	while((match=re.exec(this))!==null){
		a.push({chars:match[0].length,index:match.index});
	}
	return a;
};
String.prototype.caseReplace=function(o,n){
	for(var s=this,a=this.matchIndex(o),shift=0,i=0;i<a.length;i++){
		var c=n.followCase(this.substring(a[i].index,a[i].index+a[i].chars));
		s=s.atRemoveAdd(a[i].index+shift,a[i].chars,c);
		shift+=c.length-a[i].chars;
	}
	return s;
};

My code from 2016 for the hall of shame where I realized today that caseReplace could just return this.replace(o,m=>n.followCase(m)) instead.

By Anonymous, 2017-12-19 03:55:58
function sortUsers(a, b) {
  return a.last_name.localeCompare(b.last_name) * -1;
}
By Anonymous, 2018-03-06 22:44:30
// Save the files for 100 timea in case failed

try {
    for (let i; i <= 100; i++) {
        File.save();
    }
} catch (e) {
    // Save the files for 100 timea since it already failed
    for (let i; i <= 100; i++) {
        File.save();
    }
}
By Anonymous, 2019-09-09 18:23:39
var state = getCookie("state");
function checkCookie(args) {
  if (state == args) {
    return true;
  } else {
    alert("Request denied. Invalid auth code provided.");
    return false;
  }
}
const tokenElement = document.getElementsByName("dream");
var loginSrv = checkCookie(getAllUrlParams().state);
document.cookie = `state=${getAllUrlParams().state}; path=/`;
tokenElement.innerText = getAllUrlParams().code;
if (getAllUrlParams().state != loginSrv) {
  alert(`Incorrect auth code provided. The correct code is ${state}`);
}

If they provide the wrong oauth state code, tell the user the correct one!

By Demonitized, 2020-08-31 22:12:37
if (code === null) {
    return null;
} else {
    return code;
}
By crossthedev, 2018-11-19 15:33:47
function resetfields_simple()
{
	pole1=document.getElementById('dataOd');
	pole1.value='';
	pole2=document.getElementById('dataDo');
	pole2.value='';
	pole3=document.getElementById('trescKom');
	pole3.value='';	
	pole4=document.getElementById('katId');
	pole4.value='';	
}

function resetfields()
{
	pole1=document.getElementById('dataOd');
	pole1.value='';
	pole2=document.getElementById('dataDo');
	pole2.value='';
	pole3=document.getElementById('trescKom');
	pole3.value='';	
	pole4=document.getElementById('dokId');
	pole4.value='';	
	pole5=document.getElementById('katId');
	pole5.value='';	
	pole6=document.getElementById('currId');
	pole6.value='';		
}

function resetfields_arch()
{
	pole1=document.getElementById('dataOd');
	pole1.value='';
	pole2=document.getElementById('dataDo');
	pole2.value='';
	pole3=document.getElementById('trescKom');
	pole3.value='';	
	pole4=document.getElementById('dokId');
	pole4.value='';	
	pole5=document.getElementById('katId');
	pole5.value='';	
}
By javascriptowiec, 2020-06-30 21:29:57
if (!response ||
    !response.data ||
    !response.data.success ||
    response.data.success == false ) {
        //process stuff
}

Not talking about the '===' warning, here

By Anonymous, 2020-12-02 12:31:00
 const configs = {
    employeeObject: {
      // tab 0
      firstName: "",
      middleName: "",
      nickname: "",
      lastName: "",
      gender: "",
      race: "",
      title: "",
      dob: "",
      employeeIDNo: "",
      // tab 1
      userName: "",
      permissionRole: 0,
      employeeNo: "",
      phoneExt: "",
      startDate: "",
      company: "",
      division: "",
      jobDescription: "",
      businessUnit: "",
      regionId: "",
      participantStatus: "",
      costCentre: "",
      personType: "",
      comments: "",
      // tab 2
      phone1: "",
      phone2: "",
      phone3: "",
      address1: "",
      address2: "",
      address3: "",
      address4: "",
      postalCode: "",
      email: "",
    },

Why add another object with a title when you can just add a comment saying... well... nothing really...

By Mr Verster, 2022-04-08 14:19:12
let already_in = True;
while (already_in) {
    let random_index = Math.floor(arr.length * Math.random());
    let already_in = False;
    for (ex of exs) {
        if (ex.id === arr[random_index].id) {
            already_in = True;
        }
    }
}

Yes, this is JavaScript, and yes it didn't work. Found while reviewing some code

By L., 2021-05-17 11:20:12
if(typeof(sortOrder) != "boolean"){        
    return items;
}
filtered.sort(function (a, b) {
    if(sortOrder == true){
        return (CustomOrder(a.status) > CustomOrder(b.status) ? 1 : -1);
    }
    else if(sortOrder == false){
        return (CustomOrder(a.status) < CustomOrder(b.status) ? 1 : -1);
    }
});

The status property is a string ("Started", "Running", "Failed", "Finished", etc.), and CustomOrder is a function with a switch that just returns a predefined integer for each string. I switched CustomOrder to just be a simple lookup table object, and the sort call was changed to filtered.sort((a, b) => CustomOrder[a.status] - CustomOrder[b.status]);

By Anonymous, 2017-12-13 00:06:25
<Image source={ this.props.pickupOrDropoff == "pickup"
                                    ? i.pickup
                                    ? iconBlue
                                    : iconWhite
                                    : i.dropoff 
                                    ? iconBlue
                                    : iconWhite} style={{
                                      height:this.props.pickupOrDropoff == "pickup"
                                    ? i.pickup
                                    ? 30
                                    : i.sign === 'D' ? 30 : 35
                                    : i.dropoff 
                                    ? 30
                                    : i.sign === 'D' ? 30 : 35,
                                    marginRight:10 ,
                                    width: this.props.pickupOrDropoff == "pickup"
                                    ? i.pickup
                                    ? 40
                                    : 40
                                    : i.dropoff 
                                    ? 40
                                    : 40
                                    ,resizeMode:'contain'}}/>

I love when the code is neat...

By Fluttershy, 2019-03-05 11:40:08
 filterForProvincia() {
    console.log('ciao');
 }

The last line of code of a parting Developer

By Anonymous, 2019-07-23 11:31:51
pageEndReached() {
      if (!this.endOfResults) {
        //load more pages
        this.page++;
        this.getPosts();
      followerCount: null,
      postCount: null,
      measurementKeys: ["a", "b", "c", "d", "e"],
      showDrafts: false,
    };
  },

nani

By sonic, 2021-06-08 22:52:01
scrollToEl($el.parent().parent().parent());

Someones idea of how to select an element to scroll to.... Please no.

By Anonymous, 2019-09-27 15:20:17
socket.on('newMessage', (messageObj) => {
	if (roomNumber === messageObj.roomNumber) {

		console.log("message received:" + messageObj.message);
		$('#messages').append($('<li>').text(messageObj.userName + ' : ' + messageObj.message));

	}
});

socket.in wasn't behaving as advertised (broadcasting to all rooms). I decided to take matters into my own hands.

By Andrew, 2017-12-13 02:57:58