let showDots = typeof project.showDots === 'boolean' ? project.showDots : false;
if (showDots) {
// Somecode ...
}
Why, just why??
if (botCount < botCount)
this.reconnect();
}
My friend wrote this code recently
$options.splice($options.indexOf('option7'), 1);
$options.splice($options.indexOf('option5'), 1);
$options.splice($options.indexOf('option4'), 1);
$options.splice($options.indexOf('option3'), 1);
$options.splice($options.indexOf('option2'), 1);
$options.splice($options.indexOf('option1'), 1);
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
//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;");
})();
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...
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.
(this.router.state['view']['data'] || {})['menuOpen'] && this.router.navigateBack();
That's how pros are javascripting
function deleteConfirm() {
var result = confirm("Are you sure to delete this customer ?");
if (result) {
return true;
} else {
return false;
}
}
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!
return isDisabled == false ? false : true;
// var array = retrieveArrayValue();
var filteredArray = array.filter(function (element, index, array) {
return array.indexOf(element) == index;
});
// processArray(filteredArray);
set_locations(locations){
return new Promise((resolve, reject) => {
this.locations = locations;
resolve();
});
}
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
Handlebars.registerHelper("compare", function(a, operator, b) {
var result = false;
try {
switch (operator) {
case "==":
// eslint-disable-next-line eqeqeq
result = a == b;
break;
case "===":
result = a === b;
break;
case "!=":
// eslint-disable-next-line eqeqeq
result = a != b;
break;
case "!==":
result = a !== b;
break;
case "<":
result = a < b;
break;
case ">":
result = a > b;
break;
case "<=":
result = a <= b;
break;
case ">=":
result = a >= b;
break;
case "typeof":
// eslint-disable-next-line valid-typeof
result = typeof a === b;
break;
default: {
throw new Error(
"helper {{compare}}: invalid operator: ' + ".concat(operator, " + '")
);
}
}
} catch (err) {
console.error("\n********** ".concat(err, "."));
}
return result;
});