Skip to content

Instantly share code, notes, and snippets.

View droidjahangir's full-sized avatar

jahangir alam droidjahangir

  • Dhaka,Bangladesh
View GitHub Profile
lst = []
primeNumberList = []
# input from user
lst = [int(item) for item in input("Enter the list items : ").split(",")]
# check prime number
def prime(n):
if n <= 0:
class Department {
// private readonly id: string;
// private name: string;
private employees: string[] = [];
constructor(private readonly id: string, public name: string) {
// this.id = id;
// this.name = n;
}
}
class Department {
private id: string;
private name: string;
private employees: string[] = [];
constructor(id: string, n: string) {
this.id = id;
this.name = n;
}
//...
class Department {
name: string;
employees: string[] = [];
constructor(n: string) {
this.name = n;
}
addEmployee(employee: string) {
// + validation here (etc.)
class Department {
name: string;
constructor(n: string) {
this.name = n;
}
describe(this: Department) {
console.log('Department: ' + this.name);
}
const hobbiesArr = ['Sport', 'Cooking'];
// const hobby1 = hobbiesArr[0];
// const hobby2 = hobbiesArr[1];
const [hobby1, hobby2, ...remainingHobbies] = hobbiesArr; // doesn't mutate your original array
const personObj = {
firstName: 'Max',
ageNum: 30,
// const add = (...numbers: number[number, number, number]) => {
const addNumber = (...numbers: number[]) => {
return numbers.reduce((acc, num) => acc + num, 0);
};
const addedNumbers = addNumber(1, 3, 10, 5.5, 3.7);
console.log(addedNumbers);
const hobbies = ['Sports', 'Cooking'];
const activeHobbies = ['Hiking'];
activeHobbies.push(...hobbies);
// const activeHobbies = ['Hiking', ...hobbies];
const person = {
name: 'Max',
age: 30,
};
// default value added
const add = (a: number, b: number = 1) => a + b;
const printOutputFunc: (a: number | string) => void = (output) =>
console.log(output);
printOutputFunc(add(5));
const printOutput: (a: number | string) => void = (output) =>
console.log(output);
const button = document.querySelector('button');
if (button) {
button.addEventListener('click', (event) => console.log(event));
}