123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- //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,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>'
- console.log(currency)
- for (let letter of currency){
- str += '<td>'+letter+'</td>'
- console.log(letter)
- }
- str += '</tr>'
- }
- 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'>"
- for (let currency of arr){
- str += '<tr>'
- for (let letter of currency){
- str += '<td>'+letter+'</td>'
- }
- str+= '</tr>'
- }
- 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
- {
- let str = prompt('Введите строку').split(' ')
- const capitalize = str => {
- let result = str[0].toUpperCase()+str.toLowerCase().slice(1)
- return result
- }
- let arr = str.map(capitalize).join(' ')
- alert(arr)
- }
- //Filter Lexics
- const arr = ['бляха', 'муха', "пляха", "шабля"]
- let motherWord = prompt('Введите строку').split(' ')
- let result = motherWord.filter(element => arr.indexOf(element)=== -1)
- alert(result.join(' '))
- //Beep Lexics
- {
- const arr = ['бляха', 'муха', "пляха", "шабля"]
- let motherWord = prompt('Введите строку').split(' ')
- let arr2 = []
- for (let el of arr){
- motherWord = motherWord.map(x => x===el ?x='BEEP':x)
- }
- alert(motherWord.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)
- }
|