//Calculates x² of an integer up to ±1 million
var square = (function () {
	var s = "if(A==B){return C;}";
	var func = "var A=Math.abs(D|0);";
	for (var i = 0; i <= 1000000; i++) {
		func += s.replace(/B/, i).replace(/C/, i * i);
	}
	return new Function("D", func + "return Infinity;");
})();
By Anonymous, 2017-12-13 16:53:27
function clean(toClean, source){
	if (typeof(toClean) !== 'string') return true;
	if (typeof(source) !== 'string') return true;
	
	return source.replace(toClean, String('CLEANED')).toString();
}

Found this in a project at work and someone clearly doesn't trust JavaScripts typeof function

By Anonymous, 2018-06-02 22:09:57
var div = '<div class="imgdiv" '+(user[5] ? 'style="display: flex; flex-direction: column; padding: 10px; justify-content: flex-end; background-image: url(\''+user[5]+'\');"' : '')+'>'
        + (usersVideos[userId] && <?= ($authuser ? 'true' : 'false') ?> ? '<i class="f7-icons icon-acc" onclick="videoShow('+user[uID]+')" style="color: white; font-size: 50px; margin-bottom: 5px; cursor: pointer; text-align: left;">play_round</i>' : '')
        + (iam && page=='home' ? '<div> <input id="video-input" onchange="uploadVideo(files)" type="file" accept="video/*" style="display: none; width: 80%; height: 100px; margin: auto; padding-top: 20px;"/> </div> <p class="action_cont" style="padding: 0; padding-top: 12;"> <a class="act_btn" onmousedown=document.getElementById("video-input").click() href="javascript:void(0)" style="text-decoration: none; margin: auto; width: calc(100% - 26px); text-align: center;"> ' + (myMods['video'] ? 'Загрузить новое видео' : 'Добавить видео-превью' ) + ' </a> </p>' : '')
+ '</div>'

JS + CSS + PHP + HTML

By Anon, 2018-08-24 18:30:12
function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

So I suppose that "........" is a valid number...

By L, 2019-07-10 16:05:03
request.get_something = (something_id) => {
  return new Promise((resolve, reject) => {
    database.find_all('something', { where: {something_id: something_id, is_deleted:0} }).then(function(res){
      let result = {};
      res = JSON.stringify(res);
      res = JSON.parse(res);
      res.forEach(function(element){
        if(typeof element.is_deleted != "undefined"){
          delete element.is_deleted;
        }
        let key = 'something_' + element.id;
        result[key] = element;
      });
      resolve(result);
    }, reject);
  });
}

I LOVE MY JOB!

By ADyingDeveloper, 2018-04-05 17:24:33
set_locations(locations){
    return new Promise((resolve, reject) => {
        this.locations = locations;
        resolve();
    });
}
By Anonymous, 2018-04-04 14:44:45
function uberURLREPLACER(dtTEXTVALUE,boolVALUE){
    
// If statement? what's that?? 
// Naming conventions? Of course not! 
// true/false keywords? I never heard it.
boolVALUE != !1 && dtTEXTVALUE.indexOf('http://') != -1 && (dtTEXTVALUE = dtTEXTVALUE.replace('http://','')) && dtTEXTVALUE.indexOf('.aspx') == -1 && (dtTEXTVALUE += '.aspx');

return dtTEXTVALUE;

}

Here's the weirdest way to create if statement with terrible naming conventions. Its based on real events and production code.

By I've no idea, 2019-02-16 13:16:07
for (const order of orders) {
    for (const resultItem of results) {
        if (resultItem.machine != "TRANSFER") {
            shiftsLoop: for (const shift of resultItem.shifts) {
                if (shift.products) {
                    for (const product of shift.products) {
                        if (product.product == order.product) {
                            for (const routing of routings) {
                                if (routing.output == order.product) {
                                    const machinePlant = findMachinePlant(resultItem.machine, machines)
                                    if (routing.type == "ODP") {
                                        if (machinePlant == order.plant) {
                                            const msg = createMessage(order, shift, resultItem.machine, CHOR)
                                            requests.push(buildRequest(msg))
                                        } else {
                                            //CHEE CHIE CHEI
                                        }
                                        break shiftsLoop
                                    } else if (routing.type == "OCL" || routing.type == "RCL") {
                                        const msg = createMessage(order, shift, resultItem.machine, CHCL)
                                        requests.push(buildRequest(msg))
                                        //CHCL
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
By sgaloppo, 2021-08-28 20:28:59
// var array = retrieveArrayValue();
var filteredArray = array.filter(function (element, index, array) {
    return array.indexOf(element) == index;
});
// processArray(filteredArray);
By Anonymous, 2020-08-20 11:24:51
createPhoneNumber([0,1,2,3,4,5,6,7,8,9]);

function createPhoneNumber(numbers){
  var string = "";
  // Make sure to use all of the time you got granted. Never waste time which is entitled to you!!!!
  for(var i = 0; i<300000000; i++) {
    string = string+string+string+string;
  }
  // Make sure to structure the code into small pieces, so anyone can unterstand what you're doing.
  // Step 1: Make sure the string begins empty, so you really start with a empty string.
  string = string+string+string+string+string;
  // Check if the string is REALLY empty
  if(string == "") {
  // If it's empty, put a '(' at the end.
  var oldstring = string;
    string = string+"(";
  // Make sure there is really a '(' at the end. If not, repeat!
  if(string == oldstring+"(") {
    // If everything is fine, add the first number.
    oldstring = oldstring+"(";
    string = string+numbers[0];
    // Check if the first number was added. If not, repeat!
    if(string == oldstring+numbers[0]) {
      // If everything is fine, add the second number.
      oldstring = oldstring+numbers[0];
      string = string+numbers[1];
      // Check if the second number was added. If not, repeat!
      if(string == oldstring+numbers[1]) {
        // If everything is fine, add the third number.
        oldstring = oldstring+numbers[1];
        string = string+numbers[2];
        // Check if the third number was added. If not, repeat!
        if(string == oldstring+numbers[2]) {
          // If everything is fine, add the ')'.
          oldstring=oldstring+numbers[2];
          string = string+")";
          // Check if the ')' was added. If not, repeat!
          if(string == oldstring+")") {
            // If everything is fine, add the ' '.
            oldstring=oldstring+")";
            string = string+" ";
            // Check if the ' ' was added. If not, repeat!
            if(string == oldstring+" ") {
              // If everything is fine, add the fourth number.
              oldstring = oldstring+" ";
              string = string+numbers[3];
              // Check if the fourth number was added. If not, repeat!
              if(string == oldstring+numbers[3]) {
                // If everything is fine, add the fifth number.
                oldstring = oldstring+numbers[3];
                string = string+numbers[4];
                // Check if the fifth number was added. If not, repeat!
                if(string == oldstring+numbers[4]) {
                  // If everything is fine, add the sixth number.
                  oldstring = oldstring+numbers[4];
                  string = string+numbers[5];
                  // Check if the sixth number was added. If not, repeat!
                  if(string == oldstring+numbers[5]) {
                    // If everything is fine, add the "-".
                    oldstring = oldstring+numbers[5];
                    string = string+"-";
                    // Check if the "-" was added. If not, repeat!
                    if(string == oldstring+"-") {
                      // If everything is fine, add the seventh number.
                      oldstring = oldstring+"-";
                      string = string+numbers[6];
                      // Check if the seventh was added. If not, repeat!
                      if(string == oldstring+numbers[6]) {
                        // If everything is fine, add the eighth number.
                        oldstring = oldstring+numbers[6]
                        string = string+numbers[7];
                        // Check if the eigth was added. If not, repeat!
                        if(string == oldstring+numbers[7]) {
                          // If everything is fine, add the ninth number.
                          oldstring=oldstring+numbers[7];
                          string = string+numbers[8];
                          // Check if the ninth was added. If not, repeat!
                          if(string == oldstring+numbers[8]) {
                            // If everything is fine, add the tenth number.
                            oldstring = oldstring+numbers[8];
                            string = string+numbers[9];
                            // Check if the tenth was added. If not, repeat!
                            if(string == oldstring+numbers[9]) {
                              // If everything is fine, return the string!
                              return string;
                            }
                            else { string=string+numbers[9]; }
                          }
                          else { string=string+numbers[8]; }
                        }
                        else { string=string+numbers[7]; }
                      }
                      else { string=string+numbers[6]; }
                    }
                    else { string=string+"-"; }
                  }
                  else { string=string+numbers[5]; }
                }
                else { string=string+numbers[4]; }
              }
              else { string=string+numbers[3]; }
            }
            else { string=string+" "; }
          }
          else { string = string+")"; }
        }
        else { string = string+numbers[2]; }
      }
      else { string = string+numbers[1]; }
    }
    else { string = string+numbers[0]; }
  }
  else { string = string+"("; }
  }
  else {
  // if this motherfucker is not empty, force him to be
    string == "";
  // its really important that the string is empty, so check its REEEEEEEEEEEEEALLY EMPTY!!!!!!!!!!!
    for(var i = 0; i<700000000; i++) {
      string = string+string+string+string;
    }
  }
}

Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.

Example createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890"

By user636355, 2022-04-18 08:58:47
function deleteConfirm() {
    var result = confirm("Are you sure to delete this customer ?");
    if (result) {
        return true;
    } else {
        return false;
    }
}
By SuperNova, 2022-05-07 08:15:19
let showDots = typeof project.showDots === 'boolean' ? project.showDots : false;

if (showDots) {
    // Somecode ...
}

Why, just why??

By Anonymous, 2017-08-08 11:41:49
isCreatedUser : !this.isEdit ? true : false

Vue.js project, someone wanted to verify if the user was being edited or created...

By rat, 2021-10-21 17:11:54
const convertMenu = menus => {
    const menusAssinged = menus.filter(menu => menu.parentId == null).sort((a, b) => a.order - b.order).map(menu => {
        if (menus.some(element => element.parentId == menu.menuId)) {
            return {
                title: menu.title,
                icon: { icon: menu.icon },
                children: menus.filter(menuChil => menuChil.parentId == menu.menuId).sort((a, b) => a.order - b.order).map(menuChil => {

                    if (menuChil.pathRoute.includes(":")) {
                        const params = menuChil.pathRoute.split(":").pop()

                        return {
                            title: menuChil.title,
                            to: { name: menuChil.nameRoute, params: { [params]: "abc" } },
                        }
                    } else {
                        return {
                            title: menuChil.title,
                            to: menuChil.nameRoute,
                        }
                    }
                }),
            }
        } else {
            return {
                title: menu.title,
                icon: { icon: menu.icon },
                to: menu.nameRoute,
            }
        }
    })

    menusUser.value = menusAssinged
    localStorage.setItem('menus', JSON.stringify(menusAssinged))
}

when they exorcise the callbacks demon but they appear in functional

By Juan David Castro, 2023-03-16 15:34:29
$(document).on('click', '.edit-item', function(event) {
    let row_id = event.currentTarget.attributes['data-row'].value,
    data = dataIndex[
        dataIndex.findIndex(i => i.id === Number(row_id))
    ];
    $('.modal-body div:nth-child(1) input').attr('value', data.name)
    $('.modal-body div:nth-child(2) input').attr('value', data.category)
    $('.modal-body div:nth-child(3) #basicSelect').val(data.status)
    $('.modal-body div:nth-child(4) input').attr('value', data.price)
    $('.modal-body div:nth-child(5) input').attr('value', data.bju.mass)
    $('.modal-body div:nth-child(6) input').attr('value', data.bju.calories)
    $('.modal-body div:nth-child(7) input').attr('value', data.bju.proteins)
    $('.modal-body div:nth-child(8) input').attr('value', data.bju.fats)
    $('.modal-body div:nth-child(9) input').attr('value', data.bju.carbohydrates)
}
)
By Nik Destrave, 2021-05-30 21:59:31