Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- const ArrayHouse = [
- {
- name: 'house1',
- rooms: [
- {
- number: 3,
- chairs: [
- {
- color: 'red',
- height: 10,
- width: 45
- },
- {
- color: 'red',
- height: 10,
- width: 45
- },
- {
- color: 'red',
- height: 10,
- width: 45
- }
- ]
- },
- {
- number: 1,
- chairs: [
- {
- color: 'green',
- height: 10,
- width: 45
- },
- {
- color: 'black',
- height: 10,
- width: 45
- },
- {
- color: 'violet',
- height: 10,
- width: 45
- }
- ]
- }
- ]
- },
- {
- name: 'house2',
- rooms: [
- {
- number: 3,
- chairs: [
- {
- color: 'red',
- height: 10,
- width: 45
- },
- {
- color: 'red',
- height: 10,
- width: 45
- },
- {
- color: 'red',
- height: 10,
- width: 45
- }
- ]
- },
- {
- number: 1,
- chairs: [
- {
- color: 'green',
- height: 10,
- width: 45
- },
- {
- color: 'black',
- height: 10,
- width: 45
- },
- {
- color: 'violet',
- height: 10,
- width: 45
- }
- ]
- },
- {
- number: 15,
- chairs: [
- {
- color: 'green',
- height: 102,
- width: 45
- },
- {
- color: 'white',
- height: 110,
- width: 45
- },
- {
- color: 'violet',
- height: 150,
- width: 45
- }
- ]
- }
- ]
- }
- ]
- class HouseContext {
- constructor() {
- console.log(this.getHouseByName('house1'));
- this.addHouse({
- name: 'addHouse',
- rooms: []
- });
- console.log(ArrayHouse);
- console.log(this.getRoomBuNumber('house2', 1));
- this.addRoom('addHouse', {
- number: 228,
- chairs:[]
- });
- console.log(ArrayHouse);
- }
- getHouseByName(name) {
- return ArrayHouse.find(v => v.name == name);
- }
- addHouse(house) {
- ArrayHouse.push(house);
- }
- getRoomBuNumber(houseName, roomNumber) {
- return ArrayHouse.find(v => v.name == houseName).rooms.find(v => v.number == roomNumber);
- }
- addRoom(houseName, room) {
- ArrayHouse.find(v => v.name == houseName).rooms.push(room);
- }
- }
- new HouseContext();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement