Front end darsliklari moduli html, css, javascript


Write a function that inserts a white space between every instance of a lower character followed immediately by an upper character. Examples


Download 105.45 Kb.
bet9/12
Sana15.02.2023
Hajmi105.45 Kb.
#1200512
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
FRONT END full notes (7) (2022 05 08 17 42 47 UTC)

4.
Write a function that inserts a white space between every instance of a lower character followed immediately by an upper character.
Examples
insertWhitespace("SheWalksToTheBeach") ➞ "She Walks To The Beach"


insertWhitespace("MarvinTalksTooMuch") ➞ "Marvin Talks Too Much"


insertWhitespace("TheGreatestUpsetInHistory") ➞ "The Greatest Upset In History"

8. JAVASCRIPT – Arraylar va Looplar
• Array nima?
• Array Methodlari: index, length, json.stringify(),
slice, splice, join(), concat(),
push(), pop(), shift(), unshift()
• Map, reduce, sort, filter, forEach
• new Array('Apple', 'Banana’)// […], new Array(2) // length,

forEach()
const numbers = [65, 44, 12, 4];
numbers.forEach(myFunction)

function myFunction(item, index, arr) {
arr[index] = item * 10;
}

reduce()
const array1 = [1, 2, 3, 4];
const reducer = (previousValue, currentValue) => previousValue + currentValue;

// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10

// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15

reduce(function callbackFn(previousValue, currentValue, currentIndex, array) { ... }, initialValue)

two dimensional array


var items = [
[1, 2],
[3, 4],
[5, 6]
];

• destructure


var yourArr = [1, 2, 3]
[one, , three] = yourArray
9. JAVASCRIPT – Objects and Classes
• Object nima?
access obj value with dot and []
const person = {
fname:" John",
lname:" Doe",
age: 25
};

for (let x in person) {
txt += person[x];
}
person.nationality = "English";

delete person.age;
or delete person["age"];

const myObj = {
name: "John",
age: 30,
cars: [
{name:"Ford", "models":["Fiesta", "Focus", "Mustang"]},
{name:"BMW", "models":["320", "X3", "X5"]},
{name:"Fiat", "models":["500", "Panda"]}
]
}
acces nested objs

Obj add, delete, update


Object.keys(), Object.values(), Object.entries() [ [‘key’, ‘value’] ]

const object1 = {


a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]

const object1 = {


a: 'somestring',
b: 42
};
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
// expected output:
// "a: somestring"
// "b: 42"
obj.freeze, obj.seal
The Object.freeze() method freezes an object. A frozen object can no longer be changed; freezing an object prevents new properties from being added to it,
const obj = {
prop: 42
};
Object.freeze(obj);

obj.prop = 33;


// Throws an error in strict mode
console.log(obj.prop);
// expected output: 42

The Object.seal() method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of present properties can still be changed as long as they are writable.
const object1 = {
property1: 42
};

Object.seal(object1);


object1.property1 = 33;
console.log(object1.property1);
// expected output: 33

delete object1.property1; // cannot delete when sealed


console.log(object1.property1);
// expected output: 33

• Functions in obj


const person = {
firstName: "John",
lastName: "Doe",
id: 5566,
fullName: function() {
return this.firstName + " " + this.lastName;
}
};
arrow functions and functions in obj
• Classes —> destructure
class Car {
constructor(name, year) {
this.name = name;
this.year = year;
}
}
let myCar = new Car("Ford", 2014);
class ClassName {
constructor() { ... }
method_1() { ... }
method_2() { ... }
method_3() { ... }
}

class Car {
constructor(name, year) {
this.name = name;
this.year = year;
}
age() {
let date = new Date();
return date.getFullYear() - this.year;
}
}

inhreited classes



class Car {
constructor(brand) {
this.carname = brand;
  }
present() {
return 'I have a ' + this.carname;
  }
}

class Model extends Car {
  constructor(brand, mod) {
super(brand);
this.model = mod;
  }
show() {
 return this.present() + ', it is a ' + this.model;
  }
}

let myCar = new Model("Ford", "Mustang");
• this keyword
const person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};

Download 105.45 Kb.

Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   12




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling