form = JSON.parse(JSON.stringify(this.mobilityDistanceForm.getRawValue()));
const ITEM_COUNT = 100
let visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
function showItem(index) {
visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
visibleItems[index] = true
}
It was more or less like this. The guy had a collection of React components and wanted to show only one of them at a time. Instead of storing the index of the component to show at the moment, he decided that a boolean array would work much better. O(n) in runtime and space and null readability just because.
public void updateCurrency() {
LOGGER.info("Update currencies");
var ok = false;
try {
getExchangeRatesMechanism(getExchangeRatesProcessor());
ok = true;
} catch (Exception exception) {
LOGGER.error(exception.getMessage(), exception);
}
if (ok) {
LOGGER.info("The currencies were updated successfully!");
}
}
var lightBox_ReplaceSelectsWithSpans = function()
{
var selects = document.getElementsByTagName('select');
for (var i = 0; i < selects.length; i++) {
var select = selects[i];
if (select.clientWidth == 0 || select.clientHeight == 0 ||
select.nextSibling == null || select.nextSibling.className == 'selectReplacement') {
continue;
}
var span = document.createElement('span');
// this would be "- 3", but for that appears to shift the block that contains the span
// one pixel down; instead we tolerate the span being 1px shorter than the select
span.style.height = (select.clientHeight - 4) + 'px';
span.style.width = (select.clientWidth - 6) + 'px';
span.style.display = 'inline-block';
span.style.border = '1px solid rgb(200, 210, 230)';
span.style.padding = '1px 0 0 4px';
span.style.fontFamily = 'Arial';
span.style.fontSize = 'smaller';
span.style.position = 'relative';
span.style.top = '1px';
span.className = 'selectReplacement';
span.innerHTML = select.options[select.selectedIndex].innerHTML ;//+
//'<img src="custom_drop.gif" alt="drop down" style="position: absolute; right: 1px; top: 1px;" />';
select.cachedDisplay = select.style.display;
select.style.display = 'none';
select.parentNode.insertBefore(span, select.nextSibling);
}
};
else if result !== true && result === false { return result !== true }
should I keep this in our project or nah
let arr = []
if(arr[record.id]) {
arr[record.id] = false
} else {
arr[record.id] = false
}
this.setState({a: arr})
arr = []
function urlREPLACER(dtTEXTVALUE){
dtTEXTVALUE.indexOf('http://') != -1 && (dtTEXTVALUE = dtTEXTVALUE.replace('http://','')) && dtTEXTVALUE.indexOf('.aspx') == -1 && (dtTEXTVALUE += '.aspx');
return dtTEXTVALUE;
}
$("#search-submit").click(function() {
$("#search form").submit()
});
type="submit"
is too mainstream, jquery is the proper way to do it
function changePassword() {
if (isInputEmpty()) {
$.ajax({
type: 'POST',
data: '...'
url: '...',
success: function (result) {
if (result.substring(0, 3) != "!!!") {
//success
} else {
//faliure
}
},
error: function () {
}
});
}
}
And of course,in production, it always reported success and never changed the password, because of equally bad server code.
if(date.getFullYear() <= 2017) {
if(date.getMonth() <= 11) {
if(date.getDate() <= 26) {
if(date.getHours() <= 23) {
if(date.getMinutes() <= 59) {
if(date.getSeconds() <= 59) {
//Display popup before 2017-11-27
}
}
}
}
}
}
var i = 0
for (var n in array) {
i+=1
// ...
}
var move=0;
var kier=0;
var pic=0;
var rol=0;
var rol2=171;
var rol3=343;
var rol4=514;
var rol2_cel=171;
var rol3_cel=343;
var rol4_cel=514;
function onpic(p) {
pic=p;
}
function offpic(p) {
if( pic==p ) pic=0;
}
function next() { if(move<40) move = 40; kier=0; }
function prev() { if(move<40) move = 60; kier=1; }
function set() {
document.getElementById('ba1').style.left=0;
document.getElementById('ba2').style.left=rol2;
document.getElementById('ba3').style.left=rol3;
document.getElementById('ba4').style.left=rol4;
}
function SetOpacity(object,opacityPct)
{
// IE.
object.style.filter = 'alpha(opacity=' + opacityPct + ')';
// Old mozilla and firefox
object.style.MozOpacity = opacityPct/100;
// Everything else.
object.style.opacity = opacityPct/100;
}
var randtim=new Array(110,103,130,125,108,118,112,122,101,100);
var showtimer=0;
var showpic=1;
function Animuj() {
if( pic==0 ) {
rol2_cel=171;
rol3_cel=343;
rol4_cel=514;
} else if( pic==1 ) {
rol2_cel=342;
rol3_cel=457;
rol4_cel=571;
} else if( pic==2 ) {
rol2_cel=115;
rol3_cel=457;
rol4_cel=571;
} else if( pic==3 ) {
rol2_cel=114;
rol3_cel=229;
rol4_cel=571;
} else if( pic==4 ) {
rol2_cel=114;
rol3_cel=228;
rol4_cel=344;
}
var a = (rol2-rol2_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
if( rol2!=rol2_cel ) rol2-= a;
var a = (rol3-rol3_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
if( rol3!=rol3_cel ) rol3-= a;
var a = (rol4-rol4_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
if( rol4!=rol4_cel ) rol4-= a;
set();
document.getElementById('ba2').style.left=rol2;
showtimer+=1;
if(showtimer>100) {
for( st=0; st<9; ++st ) {
if(showtimer==randtim[st]) { SetOpacity(document.getElementById("ps"+st), 0); document.getElementById("ps"+st).style.backgroundImage="url('cs/log"+showpic+".jpg')"; }
if(showtimer==(randtim[st]+1)) SetOpacity(document.getElementById("ps"+st),20);
if(showtimer==(randtim[st]+2)) SetOpacity(document.getElementById("ps"+st),40);
if(showtimer==(randtim[st]+3)) SetOpacity(document.getElementById("ps"+st),60);
if(showtimer==(randtim[st]+4)) SetOpacity(document.getElementById("ps"+st),80);
if(showtimer==(randtim[st]+5)) { document.getElementById("pn"+st).style.backgroundImage="url('cs/log"+showpic+".jpg')"; SetOpacity(document.getElementById("ps"+st),0); }
}
if(showtimer>150) {
showtimer=0;
for( st=0; st<9; ++st ) randtim[st]=Math.floor(Math.random()*26)+100;
showpic+=1; if(showpic>2) showpic=0;
}
}
}
window.setInterval("Animuj()", 50);
This is how public money is spent in poland
function add(input1,input2) {
var number1 = input1.toString();
var number2 = input2.toString();
var numbers1 = new Array();
var numbers2 = new Array();
var size1 = 0;
var size2 = 0;
while(size1 < number1.length) {
var SizeAndNumberToAddToNumbers1Array = 0;
var Number1FromFunctionAddLength = number1.length-size1-1;
SizeAndNumberToAddToNumbers1Array = number1.charAt(size1);
while(Number1FromFunctionAddLength > 0){
SizeAndNumberToAddToNumbers1Array = SizeAndNumberToAddToNumbers1Array + "0";
Number1FromFunctionAddLength = Number1FromFunctionAddLength-1;
}
numbers1.push(SizeAndNumberToAddToNumbers1Array);
size1 = size1 + 1;
}
while(size2 < number2.length) {
var SizeAndNumberToAddToNumbers1Array2 = 0;
var Number1FromFunctionAddLength2 = number2.length-size2-1;
SizeAndNumberToAddToNumbers1Array2 = number2.charAt(size2);
while(Number1FromFunctionAddLength2 > 0){
SizeAndNumberToAddToNumbers1Array2 = SizeAndNumberToAddToNumbers1Array2 + "0";
Number1FromFunctionAddLength2 = Number1FromFunctionAddLength2-1;
}
numbers2.push(SizeAndNumberToAddToNumbers1Array2);
size2 = size2 + 1;
}
var result1 = 0;
var saize1 = 0;
while(saize1 < numbers1.length){
var topush1 = numbers1[saize1];
result1=result1+parseInt(topush1);
saize1 = saize1 + 1;
}
var result2 = 0;
var saize2 = 0;
while(saize2 < numbers2.length){
var topush2 = numbers2[saize2];
result2=result2+parseInt(topush2);
saize2 = saize2 + 1;
}
return result1+result2;
}
advanced and optimized add function better than a + b
function isEmpty(value) {
if (value === '') {
return false;
} else if (value === 0) {
return false;
} else if (value === null) {
return false;
} else if (value === undefined) {
return false;
} else {
return true;
}
return true;
}
javascript empty value check
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.