|
@@ -0,0 +1,251 @@
|
|
|
+//Confirms
|
|
|
+{
|
|
|
+ const arr = [confirm('Ты мужчина?'),confirm('Ты женщина?'),confirm('Тебе больше 18-ти лет?')]
|
|
|
+ console.log(arr)//[true, false, true]
|
|
|
+}
|
|
|
+
|
|
|
+//Prompts
|
|
|
+{
|
|
|
+ const arr = []
|
|
|
+ arr[0]=prompt('Ты мужчина?')
|
|
|
+ arr[1]=prompt('Ты женщина?')
|
|
|
+ arr[2]=prompt('Тебе больше 18-ти лет?')
|
|
|
+ console.log(arr)// ['да', 'нет', 'да']
|
|
|
+}
|
|
|
+
|
|
|
+//Item access
|
|
|
+{
|
|
|
+ const arr = ['нулевой','первый','второй']
|
|
|
+ indexArr = prompt('Введите индекс массива')
|
|
|
+ console.log(arr[indexArr])
|
|
|
+}
|
|
|
+
|
|
|
+//Item change
|
|
|
+{
|
|
|
+ const arr = ['нулевой','первый','второй']
|
|
|
+ indexArr = prompt('Введите индекс массива')//если тут будет '2'
|
|
|
+ meaningArr = prompt('Введите значение для выбраного индекса')// а тут слово 'четвертый'
|
|
|
+ arr[indexArr]= meaningArr
|
|
|
+ console.log(arr)// то здесь будет такой массив ['нулевой', 'первый', 'четвертый']
|
|
|
+}
|
|
|
+
|
|
|
+//Multiply table
|
|
|
+{
|
|
|
+ //const arr = [[],[0,1,2,3,4,5,6,7,8,9,10],[0,2,4,6,8,10,12,14,16,18,20],[0,3,6,9,12,15,18,21,24,27,30],[0,4,8,12,16,20,24,28,32,36,40],[0,5,10,15,20,25,30,35,40,45,50]]
|
|
|
+ const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
|
|
|
+ console.log(arr[3][4])// ответ 12
|
|
|
+}
|
|
|
+
|
|
|
+//Multiply table slice
|
|
|
+{
|
|
|
+ const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
|
|
|
+ let arr2 = [arr[1].slice(1),arr[2].slice(1),arr[3].slice(1),arr[4].slice(1)]
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//IndexOf Word
|
|
|
+{
|
|
|
+ let str = prompt('Введите строку из несколький слов').split(' ');
|
|
|
+ let strIndex = prompt('Введите искомое слово');
|
|
|
+ let arr = str.indexOf(strIndex);
|
|
|
+ if (arr === -1){
|
|
|
+ alert('Слово не найдено');
|
|
|
+ }
|
|
|
+ else{alert('Ваше слово '+(arr+1)+'-е по счету');}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Reverse
|
|
|
+{
|
|
|
+ let arr = []
|
|
|
+ arr.push(prompt('Введите первый элемент'))
|
|
|
+ arr.push(prompt('Введите второй элемент'))
|
|
|
+ arr.push(prompt('Введите третий элемент'))
|
|
|
+ arr.push(prompt('Введите четвертый элемент'))
|
|
|
+ arr.push(prompt('Введите пятый элемент'))
|
|
|
+ let arr2 = []
|
|
|
+ arr2.push(arr.pop())
|
|
|
+ arr2.push(arr.pop())
|
|
|
+ arr2.push(arr.pop())
|
|
|
+ arr2.push(arr.pop())
|
|
|
+ arr2.push(arr.pop())
|
|
|
+ console.log(arr2)
|
|
|
+//Reverse 2
|
|
|
+ let arr3 = []
|
|
|
+ arr3.unshift(arr2.shift())
|
|
|
+ arr3.unshift(arr2.shift())
|
|
|
+ arr3.unshift(arr2.shift())
|
|
|
+ arr3.unshift(arr2.shift())
|
|
|
+ arr3.unshift(arr2.shift())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Copy
|
|
|
+{
|
|
|
+ const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
|
|
|
+ const arr2 = arr
|
|
|
+}
|
|
|
+
|
|
|
+//Deep Copy
|
|
|
+{
|
|
|
+ const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
|
|
|
+ const arr2 = arr.slice()
|
|
|
+}
|
|
|
+
|
|
|
+//Array Equals
|
|
|
+{
|
|
|
+ const arr = [1,2,3]
|
|
|
+ const arr2 = arr
|
|
|
+ arr === arr2//true
|
|
|
+}
|
|
|
+
|
|
|
+//Flat
|
|
|
+{
|
|
|
+ const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
|
|
|
+ const arr2 = [...arr[0],...arr[1],...arr[2],...arr[3],...arr[4]]
|
|
|
+ console.log(arr2.length)//25
|
|
|
+}
|
|
|
+
|
|
|
+//Destruct
|
|
|
+{
|
|
|
+ let str = prompt('Введите текст')
|
|
|
+ const [a,,,,b,,,,c] = str
|
|
|
+ alert(a+b+c)
|
|
|
+}
|
|
|
+
|
|
|
+//Destruct default
|
|
|
+{
|
|
|
+ let str = prompt('Введите текст')
|
|
|
+ const [a='!',,,,b='!',,,,c='!'] = str
|
|
|
+ alert(a+b+c)
|
|
|
+}
|
|
|
+
|
|
|
+//Multiply table rest
|
|
|
+{
|
|
|
+ const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
|
|
|
+ const [,[,...a],[,...b],[,...c],[,...d]] = arr
|
|
|
+ const arr2 = [a,b,c,d]
|
|
|
+ const arr3 = [...arr2[0],...arr2[1],...arr2[2],...arr2[3]]
|
|
|
+ console.log(arr3) // [1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16]
|
|
|
+}
|
|
|
+
|
|
|
+//For Alert
|
|
|
+{
|
|
|
+ const names = ["John", "Paul", "George", "Ringo"]
|
|
|
+ for (let name of names)
|
|
|
+ {
|
|
|
+ alert(`Hello, ${name}`)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//For Select Option
|
|
|
+{
|
|
|
+ const currencies = ["USD", "EUR", "GBP", "UAH"]
|
|
|
+ let str = "<select>"
|
|
|
+ for (let currency of currencies){
|
|
|
+ str += '<option>'+currency+'</option>'
|
|
|
+ }
|
|
|
+ str+= "</select>"
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+
|
|
|
+//For Table Horizontal
|
|
|
+{
|
|
|
+ const names = ["John", "Paul", "George", "Ringo"]
|
|
|
+ let str = "<table border='1'>"
|
|
|
+ for (let namesTable of names){
|
|
|
+ str += '<td>'+namesTable+'</td>'
|
|
|
+ }
|
|
|
+ str+= "</table>"
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//For Table Vertical
|
|
|
+{
|
|
|
+ const names = ["John", "Paul", "George", "Ringo"]
|
|
|
+ let str = "<table border='1'>"
|
|
|
+ for (let namesTable of names){
|
|
|
+ str += '<tr><td>'+namesTable+'</td></tr>'
|
|
|
+ }
|
|
|
+ str+= "</table>"
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+
|
|
|
+//For Table Letters
|
|
|
+{
|
|
|
+ const currencies = ["USD", "EUR", "GBP", "UAH"]
|
|
|
+ let str = "<table border='1'>"
|
|
|
+ for (let currency of currencies){
|
|
|
+ str += '<tr>'+currency+'</tr>'
|
|
|
+ console.log(currency)
|
|
|
+ for (let letter of currency){
|
|
|
+ str += '<td>'+letter+'</td>'
|
|
|
+ console.log(letter)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str+= "</table>"
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+
|
|
|
+//For Multiply Table
|
|
|
+{
|
|
|
+ const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
|
|
|
+ let str = "<table border='1'>"
|
|
|
+ let i = 0
|
|
|
+ for (let currency of arr){
|
|
|
+ str += '<tr>'+currency+'</tr>'
|
|
|
+ console.log(currency)
|
|
|
+ for (let letter of currency){
|
|
|
+ str += '<td>'+letter+'</td>'
|
|
|
+ console.log(letter)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str+= "</table>"
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+
|
|
|
+//Function Capitalize
|
|
|
+{
|
|
|
+ const capitalize = str => {
|
|
|
+ let result
|
|
|
+ result=str[0].toUpperCase()+str.toLowerCase().slice(1)
|
|
|
+ return result //именно этот код обеспечит возврат результата функции
|
|
|
+ }
|
|
|
+ console.log(capitalize("cANBerRa")) //Canberra
|
|
|
+}
|
|
|
+
|
|
|
+//Map Capitalize
|
|
|
+{
|
|
|
+ const capitalize = str => {
|
|
|
+ let result
|
|
|
+ result=str[0].toUpperCase()+str.toLowerCase().slice(1)
|
|
|
+ return result //именно этот код обеспечит возврат результата функции
|
|
|
+ }
|
|
|
+ str = prompt('Введите строку').split(' ')
|
|
|
+ arr = str.map(capitalize).join(' ')
|
|
|
+ alert(arr)
|
|
|
+}
|
|
|
+
|
|
|
+//Beep Lexics
|
|
|
+{
|
|
|
+ const motherWord = ['дурак']
|
|
|
+ const arr = prompt('Введите строку').split(' ')
|
|
|
+ let resultArr = arr.map(x => x===motherWord[0] ?x='BEEP':x=x).join(' ')//понимаю что это не решение, но ничего другого не придумал
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Reduce HTML
|
|
|
+{
|
|
|
+ const currencies = ["","USD", "EUR", "GBP", "UAH"]
|
|
|
+ let str = "<select>"
|
|
|
+ str += currencies.reduce( (a,b) => a+'<option>'+b+'</option>' )
|
|
|
+ str += "</select>"
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|