-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterview.js
103 lines (77 loc) · 2.67 KB
/
interview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//predictable
// function customMap(arr){
// const result = []
// // write your code here
// for(let i = 0; i < arr.length;i++){
// result.push(arr[i] + 2)
// }
// return result
// }
// console.log(customMap([1,2,3,4]));
// console.log(customMap([1,2,3,4]));
// let cart = [
// { name: 'Apple', category: 'Fruit', quantity: 10, price: 0.5 },
// { name: 'Orange', category: 'Fruit', quantity: 5, price: 0.8 },
// { name: 'Broccoli', category: 'Vegetable', quantity: 2, price: 1.5 },
// { name: 'Carrot', category: 'Vegetable', quantity: 8, price: 0.2 },
// { name: 'Chicken', category: 'Meat', quantity: 1, price: 10 }
// ]
// let cartNames = cart.map(function(value){
// return value.name
// })
// console.log(cartNames);
// const result = cart.reduce((acc, eachVal) => {
// const newObj = {};
// newObj.name = eachVal.name;
// newObj.totalPrice = eachVal.quantity * eachVal.price;
// acc.push(newObj);
// return acc;
// }, []);
// console.log(result);
// let fruits = cart.filter((value) => value.category === 'Fruit')
// let vegatables = cart.filter(value => value.category === 'Vegetable' )
// // let objeFruVeg = {
// // }
// let sumFruits = fruits.reduce((acc,value)=> acc + value,{})
// // let sumVege = vegatables.reduce((acc,value)=> acc + value)
// ================================================================================================================================================================== //
// function divisible_by_b(a,b){
// }
// function format_date(a){
// }
// function add(a,b){
// return Number(a) + Number(b)
// }
// console.log(add('111','111'));
// console.log(add('','20'));
// function list_of_Multiplies(a,b){
// let result = []
// for(let i = 1; i <= b;i++){
// result.push(a * i)
// }
// return result
// }
// console.log(list_of_Multiplies(7,5));
// function make_rug(a, b, c) {
// let result = [];
// for (let i = 0; i < a; i++) {
// let m = "";
// result.push(m);
// for (let j = 0; j < b; j++) {
// m += c;
// }
// }
// return result;
// }
// console.log(make_rug(3, 5, 'A'));
let cart = [
{ name: 'Apple', category: 'Fruit', quantity: 10, price: 0.5 },
{ name: 'Orange', category: 'Fruit', quantity: 5, price: 0.8 },
{ name: 'Broccoli', category: 'Vegetable', quantity: 2, price: 1.5 },
{ name: 'Carrot', category: 'Vegetable', quantity: 8, price: 0.2 },
{ name: 'Chicken', category: 'Meat', quantity: 1, price: 10 },
];
// let cart2 = cart;
// console.log(cart.length,cart2.length);
// cart2.pop();
// console.log(cart.length, cart2.length);