moving all labs to old dir
This commit is contained in:
10
old/lectures/lec5/p3/task1.js
Normal file
10
old/lectures/lec5/p3/task1.js
Normal file
@@ -0,0 +1,10 @@
|
||||
let items = {
|
||||
'ручка': 20,
|
||||
'альбом': "a16",
|
||||
'тетрадь': 10
|
||||
};
|
||||
|
||||
let entries = Object.entries(items);
|
||||
items=Object.fromEntries(entries.filter(entry =>!isNaN(parseFloat(entry[1]) && isFinite(Number(entry[1])))))
|
||||
|
||||
console.log(items);
|
||||
17
old/lectures/lec5/p3/task2.js
Normal file
17
old/lectures/lec5/p3/task2.js
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
function updateObject(oldObject, newObject) {
|
||||
const [newKey, newValue] = Object.entries(newObject)[0];
|
||||
if (newKey in oldObject) {
|
||||
oldObject[newKey] += newValue;
|
||||
} else {
|
||||
oldObject[newKey] = newValue;
|
||||
}
|
||||
return oldObject;
|
||||
}
|
||||
|
||||
|
||||
const oldObject = { 1: 10, 2: 20, 3: 30 };
|
||||
const newObject = { 2: 15 };
|
||||
|
||||
const updatedObject = updateObject(oldObject, newObject);
|
||||
console.log(updatedObject);
|
||||
15
old/lectures/lec5/p3/task3.js
Normal file
15
old/lectures/lec5/p3/task3.js
Normal file
@@ -0,0 +1,15 @@
|
||||
let objGoods = {
|
||||
"ручка": [100, 50.60],
|
||||
"карандаш": [120, 30.00],
|
||||
"тетрадь": [200, 10.50]
|
||||
};
|
||||
|
||||
outArr = [];
|
||||
Object.entries(objGoods).forEach((entry) => {
|
||||
let name = entry[0];
|
||||
entry[1].forEach(price => {
|
||||
outArr.push({ "name": name, amount: price })
|
||||
})
|
||||
});
|
||||
|
||||
console.log(outArr);
|
||||
11
old/lectures/lec5/p3/task4.js
Normal file
11
old/lectures/lec5/p3/task4.js
Normal file
@@ -0,0 +1,11 @@
|
||||
let items = {
|
||||
'ручка': 20,
|
||||
'альбом': 16,
|
||||
'тетрадь': 10
|
||||
};
|
||||
|
||||
let entries = Object.entries(items);
|
||||
entries.sort((a,b) => Number(a[1])-Number(b[1]));
|
||||
items=Object.fromEntries(entries)
|
||||
|
||||
console.log(items);
|
||||
Reference in New Issue
Block a user