//Arrow to Functions /* { function far (t) { let result = t * 9/5 + 32 return result } console.log(far(1) + " F") } { const red = +prompt ("Write your value for red:") const green = +prompt ("Write your value for green :") const blue = +prompt ("Write your value for blue :") function rgb (r, g, b) { r = r.toString(16) if(r.length < 2) { r = r+r } g = g.toString(16) if(g.length < 2) { g = g + g } b = b.toString(16) if(b.length < 2) { b = b + b } let result =` #${r+g+b} ` return result } console.log(rgb(red,green,blue)) } { function func () { function capitalize (str) { let result = str.split('')[0].toUpperCase() + str.slice(1,+Infinity).toLowerCase() return result //именно этот код обеспечит возврат результата функции } let firstname = capitalize(prompt("Write your name")) let surname = capitalize(prompt("Write your surname")) let fathername = capitalize(prompt("Write your thirdname")) let fullname = (firstname + " " + surname + " " + fathername) let result = {firstname, surname, fathername, fullname} return result } console.log(func()) } { const persons = [ {name: "Иван", age: 17}, {name: "Мария", age: 35}, {name: "Алексей", age: 73}, {name: "Яков", age: 12}, ] function funSort () { function results (arr, name, booln=true){ let result = arr.sort((first,second) => (first[name] < second[name]) === booln ? -1 : 1) return result } return results } console.log(funSort()(persons, "age")) console.log(funSort()(persons, "age", false )) } { const car = { "Name":"chevrolet chevelle malibu", "Cylinders":8, "Displacement":307, "Horsepower":130, "Weight_in_lbs":3504, "Origin":"USA", "in_production": false } function createObject (obj) { let str = "
" return document.write(str) } console.log(createObject(car)) } //createPerson //Создайте функцию createPerson, которая принимает два параметра: name и surname, //и возвращает объект с ключами name, surname, getFullName. getFullName должна быть функцией, //которая работает с объектом через this, //а так же готова к тому, что в объекте в последствии добавить ключ fatherName { function createPerson(name, surname) { let obj = { "name":name, fatherName:"", "surname":surname, getFullName:function (){ return `${this.name} ${this.fatherName} ${this.surname} ` } } return obj } const a = createPerson("Вася", "Пупкин") const b = createPerson("Анна", "Иванова") const c = createPerson("Елизавета", "Петрова") console.log(a) //Вася Пупкин a.fatherName = 'Иванович' c.fatherName = "Олеговна" console.log(a.getFullName()) //Вася Иванович Пупкин console.log(b.getFullName()) //Анна Иванова console.log(c.getFullName()) } //createPersonClosure { function createPersonClosure (name="Василь",surname="Василич") { let age=20 let fatherName="Васильович" let result return result = { getName: function (){return name}, getSurName : function (){return surname}, getFatherName : function (){return fatherName}, getAge : function(){return age}, getFullName : function(){ return `${name} ${surname} ${fatherName}` }, setName : function (newName){ if(newName.slice(0,1) === newName.toUpperCase().slice(0,1)){ name = newName return result.getName() } else return result.getName() }, setSurName: function(newSurName){ if(newSurName.slice(0,1) === newSurName.toUpperCase().slice(0,1)){ surname = newSurName return result.getSurName() } else return result.getSurName() }, setFatherName: function(newFatherName){ if(newFatherName.slice(0,1) === newFatherName.toUpperCase().slice(0,1)){ fatherName = newFatherName return result.getFatherName() } else return result.getFatherName() }, setAge: function(newAge){ if(newAge >= 0 && newAge < 101){ age = newAge return result.getAge() } else return result.getAge() }, setFullName: function(newFullName){ let [reName,reSurName,reFatherName] = newFullName.split(" ") if(reName.slice(0,1) === reName.toUpperCase().slice(0,1) && reSurName.slice(0,1) === reSurName.toUpperCase().slice(0,1) && reFatherName.slice(0,1) === reFatherName.toUpperCase().slice(0,1)){ [name,surname,fatherName] = newFullName.split(" ") return result.getFullName() } else return result.getFullName() } } } const a = createPersonClosure("Вася", "Пупкин") const b = createPersonClosure("Анна", "Иванова") console.log(a.getName()) console.log(a.setAge(15)) console.log(a.setAge(150)) //не работает b.setFullName("Петрова Анна Николаевна") console.log(b.getFatherName()) //Николаевна } //createPersonClosureDestruct { function createPerson(name, surname) { let obj = { "name":name, fatherName:"", "surname":surname, getFullName:function (){ return `${this.name} ${this.surname} ${this.fatherName} ` } } return obj } function createPersonClosureDestruct (person) { let {name='Василь',surname='Васильов',fatherName='Иванович',age=20} = person let result return result = { getName: function (){return name}, getSurName : function (){return surname}, getFatherName : function (){return fatherName}, getAge : function(){return age}, getFullName : function(){ return `${name} ${surname} ${fatherName}` }, setName : function (newName){ if(newName.slice(0,1) === newName.toUpperCase().slice(0,1)){ name = newName return result.getName() } else return result.getName() }, setSurName: function(newSurName){ if(newSurName.slice(0,1) === newSurName.toUpperCase().slice(0,1)){ surname = newSurName return result.getSurName() } else return result.getSurName() }, setFatherName: function(newFatherName){ if(newFatherName.slice(0,1) === newFatherName.toUpperCase().slice(0,1)){ fatherName = newFatherName return result.getFatherName() } else return result.getFatherName() }, setAge: function(newAge){ if(newAge >= 0 && newAge < 101){ age = newAge return result.getAge() } else return result.getAge() }, setFullName: function(newFullName){ let [reName,reSurName,reFatherName] = newFullName.split(" ") if(reName.slice(0,1) === reName.toUpperCase().slice(0,1) && reSurName.slice(0,1) === reSurName.toUpperCase().slice(0,1) && reFatherName.slice(0,1) === reFatherName.toUpperCase().slice(0,1)){ [name,surname,fatherName] = newFullName.split(" ") return result.getFullName() } else return result.getFullName() } } } const a = createPersonClosureDestruct(createPerson("Вася Пупкин")) const b = createPersonClosureDestruct({name: 'Николай', age: 75}) console.log(a.getName()) console.log(b.getAge()) } //isSorted + Test { let arr = [] let question while(question = +prompt("Write your element for array")){ arr.push(question) } console.log(arr) function isSorted (...params){ let firstNumber = -Infinity for (x of params){ if(typeof(x) === "number" && firstNumber