export const getUniqueIds = (ids: string[]) => {
const uniqueIds = new Set<string>();
return ids.filter((id) => {
if (!uniqueIds.has(id)) {
uniqueIds.add(id);
return true;
}
return false;
});
};
const [glossaries, prompts] = [await getGlossaries(), await getPromps()];
// instead of
// const [glossaries, prompts] = await Promise.all([getGlossaries(), getPrompts()]);
When I was writing the code, I thought for a moment that getGlossaries() and getPrompts() will be executed in parallel
// this.collectPairs() returns data from the UI form
// this.alert.alarmReasons contains empty array or alarmReason-Category pair objects
let newAlarmReasonsToAdd = []
this.collectPairs().forEach(categoryAndAlarmReasonPair => {
!!!this.searchAmidExisting(categoryAndAlarmReasonPair, this.alert.alarmReasons) ? newAlarmReasonsToAdd.push(categoryAndAlarmReasonPair) : null
})
searchAmidExisting(alarmReasonToAdd, existingAlarmReasons){
let res = existingAlarmReasons.find(existing => {
if(alarmReasonToAdd.categoryDictEntryKey === existing.category && alarmReasonToAdd.reasonDictEntryKey === existing.reason){
return true
} else return false
})
return res
}
this.unwatchBackdrop ? this.unwatchBackdrop() : this.noop();
...
private noop(): void {}
const rola = (usr: IUserData) => {
let student = "student"
let edukator = "edukator"
let dziekanat = "dziekanat"
let admin = "admin"
if(usr.type===1){
return student
}
else if(usr.type===2){
return edukator
}
else if(usr.type===3){
return dziekanat
}
else if(usr.type===4){
return admin
}
}
public array<P extends Path<NotNul<T>>, Key extends string>(
name: P,
...args: NotNul<PathValue<NotNul<T>, P>> extends Array<infer Item> ? ('id' extends keyof Item ? [keyname: Key] : [keyName?: Key]) : []
): NotNul<PathValue<NotNul<T>, P>> extends Array<infer Item>
? Key extends keyof Item
? never
: Field<Array<Item & (Key extends keyof Item ? {} : string extends Key ? {} : { [P in Key]?: string })>>
: never {
return this.createField(name as any, this.name, args[0]) as any
}
@Pipe({ name: 'shortSex' })
export class SexPipe implements PipeTransform {
public transform(value: any): 'M' | 'K' {
switch (value?.code) {
case SexCodes.MALE:
return 'M';
case SexCodes.FEMALE:
return 'K';
default:
return null;
}
}
}
What can I say more?
<ng-container *ngIf="!errors">
<div *ngIf="errors" class="no-content-wrapper">
<esel-components-error [error]="errors"></esel-components-error>
</div>
</ng-container>
Make your code error prone with effective error handling!
function generateArrayFrom1To10()
{
let a = 0;
let b = 1;
let c = 3;
let d = 4;
let e = 5;
let f = 6;
let g = 7;
let h = 8;
let i = 9;
let array = [a,b,c,d,e,f,g,h,i];
return array;
}
ngOnInit() {
this._FunctionService.getSicksList().then(res => {
let resf:any = res;
if (resf.err) {
} else {
this.diagnosticAll = resf.data
}
}, err => { })
}
/*
ngOnInit() {
this._FunctionService.getSicksList().then(res => {
this.diagnosticAll = res.data
}, err => { })
}
*/
function getJSType(cppType: string) {
let typeMap = new Map<string, string>([
["Bool", "boolean"],
["Int32", "number"],
["UInt32", "number"],
["Int64", "number"],
["UInt64", "number"],
["Double", "number"],
["String", "string"],
["Object", "any"]
]);
if (typeMap.get(cppType) === undefined) {
console.error("Invalid type in getJavascriptType: " + cppType);
process.exit(1);
}
return typeMap.get(cppType);
}
public showOrHideLegends(seriesList: any[]) {
if (seriesList.length === 0)
return false;
else
return true;
}
more code lines => more money; that's how our contractor company thinks
checkParameter(elem: boolean): any {
if(elem) return true;
return null;
}