|
| 1 | +//Task1 |
| 2 | +function testValue (value) { |
| 3 | + if (typeof value == 'number' || typeof value == 'object') { |
| 4 | + return true; |
| 5 | + }; |
| 6 | + if (typeof value == 'function') { |
| 7 | + return false; |
| 8 | + }; |
| 9 | + if (typeof value === 'string') { |
| 10 | + if(value.length != 10) { |
| 11 | + return `Длина вашей строки: ${value.length}.`; |
| 12 | + }; |
| 13 | + if (value.length == 10) { |
| 14 | + return 'you win'; |
| 15 | + }; |
| 16 | + }; |
| 17 | +}; |
| 18 | +let typeofNumber = 10; |
| 19 | +let typeofObject = { |
| 20 | + name: 'Natalia' |
| 21 | +}; |
| 22 | +let typeofFunction = function () { |
| 23 | + return 2 + 2; |
| 24 | +}; |
| 25 | +let typeofString = 'JS'; |
| 26 | +let typeofString10 = 'javascript'; |
| 27 | + |
| 28 | +console.log(testValue(typeofNumber));//true |
| 29 | +console.log(testValue(typeofObject));//true |
| 30 | +console.log(testValue(typeofFunction));//false |
| 31 | +console.log(testValue(typeofString));//'длина вашей строки: <длина строки>' |
| 32 | +console.log(testValue(typeofString10));//'you win' |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +//Task2 |
| 37 | +function numbersBetween(a, b) { |
| 38 | + let arr = []; |
| 39 | + if (typeof a !== 'number' && typeof b !== 'number') { |
| 40 | + return 'Вы ввели не числа'; |
| 41 | + } |
| 42 | + for (let i = a; i <= b; i++) { |
| 43 | + arr.push(i); |
| 44 | + }; |
| 45 | + return arr; |
| 46 | +}; |
| 47 | + |
| 48 | +console.log('numbersBetween', numbersBetween(3, 5)); |
| 49 | + |
| 50 | +console.log('numbersBetween', numbersBetween(10, 12)); |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +//Task3 |
| 55 | +function FizzBuzz(num) { |
| 56 | + let str = ''; |
| 57 | + if (num % 3 === 0) { |
| 58 | + str = str + 'Fizz'; |
| 59 | + }; |
| 60 | + if (num % 5 === 0) { |
| 61 | + str = str + 'Buzz'; |
| 62 | + }; |
| 63 | + return str.length === 0 ? num : str; |
| 64 | +}; |
| 65 | + |
| 66 | +function fizzBuzz100(number) { |
| 67 | + for (let i = number; i <= 100; i++) { |
| 68 | + FizzBuzz(i); |
| 69 | + }; |
| 70 | +}; |
| 71 | + |
| 72 | +fizzBuzz100(80); |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +//Task4 |
| 77 | +let arr = [1, null, undefined, 'str', {}, [], function() {}]; |
| 78 | +let array = `Массив – разновидность объекта.`; |
| 79 | +let typeofNull = 'null – это не объект, а отдельный тип данных'; |
| 80 | + |
| 81 | +function typesVariablesInArray (arg) { |
| 82 | + let newArr = []; |
| 83 | + for (let i = 0; i < arr.length; i++) { |
| 84 | + let type = typeof arr[i]; |
| 85 | + if (Array.isArray(arr[i])) { |
| 86 | + newArr[i] = `${type}; ${array}` |
| 87 | + } else if (arr[i] === null){ |
| 88 | + newArr[i] = `${type}; ${typeofNull}` |
| 89 | + } else { |
| 90 | + newArr[i] = type; |
| 91 | + } |
| 92 | + }; |
| 93 | + return newArr; |
| 94 | +}; |
| 95 | + |
| 96 | +console.log(typesVariablesInArray(arr)); |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +//@@SUPER@@ |
| 101 | + |
| 102 | +let array2 = Array.from({length: 35}, |
| 103 | + (value, index) => (index % 2 ? {age: index + 2} : {age: NaN}), |
| 104 | +); |
| 105 | + |
| 106 | +function solution(arr) { |
| 107 | + for (let i = 0; i < arr.length; i++) { |
| 108 | + let obj = arr[i]; |
| 109 | + if (isNaN(obj.age)) { |
| 110 | + obj.unknownAge = true; |
| 111 | + }; |
| 112 | + }; |
| 113 | +}; |
| 114 | + |
| 115 | +solution(array2); |
| 116 | + |
| 117 | +function solution2 (arr2) { |
| 118 | + let secondNewArr = []; |
| 119 | + let obj; |
| 120 | + for (let i = 0; i < arr2.length; i++) { |
| 121 | + obj = arr2[i]; |
| 122 | + if ('unknownAge' in obj) { |
| 123 | + secondNewArr[secondNewArr.length] = obj; |
| 124 | + }; |
| 125 | + }; |
| 126 | + return secondNewArr; |
| 127 | +} |
| 128 | + |
| 129 | +console.log(solution2(array2)); |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +// Classwork problem task |
| 134 | +let webStore = { |
| 135 | + category: { |
| 136 | + noteBook: ['Asus', 'Lenovo', 'Dell', 'HP'], |
| 137 | + mobile: ['Nokia', 'Apple', 'Sony'] |
| 138 | + } |
| 139 | +}; |
| 140 | + |
| 141 | +let category = webStore.category; |
| 142 | + |
| 143 | +function dataProcessing (data) { |
| 144 | + for (let key in category){ |
| 145 | + let categoryItems = category[key]; |
| 146 | + console.log(`Категория: ${key}`); |
| 147 | + for (let i = 0; i < categoryItems.length; i++){ |
| 148 | + console.log(` Содержимое категории: ${categoryItems[i]}`); |
| 149 | + }; |
| 150 | + }; |
| 151 | +}; |
| 152 | +dataProcessing(webStore); |
0 commit comments