diff --git "a/01\347\277\201\347\253\240\345\275\254/\344\275\234\344\270\232/2022-10-11.md" "b/01\347\277\201\347\253\240\345\275\254/\344\275\234\344\270\232/2022-10-11.md" new file mode 100644 index 0000000000000000000000000000000000000000..ab910f3a399f3b5774cb35db2b6fee12eb2f1739 --- /dev/null +++ "b/01\347\277\201\347\253\240\345\275\254/\344\275\234\344\270\232/2022-10-11.md" @@ -0,0 +1,154 @@ +// 使用冒泡排序: [90,65,78,66,48,39,92,73] 使用数组解构 + +```javascript +const arr = [90,65,78,66,48,39,92,73]; + +console.log(arr); + +for (var a = 0; a < arr.length; a++) { + + for (var index = 0; index < arr.length-a; index++) { + +​ if (arr[index]>arr[index+1]) { + +​ [arr[index],arr[index+1]]=[arr[index+1],arr[index]] + +​ } + + } + +} + +console.log(arr); +``` + +// javascript + +// 将数组的单词全转为大写,要求 使用箭头函数 + +```javascript +const countries = ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland']; + +const c = countries.map((countries)=>countries.toUpperCase()); + +console.log(c); +``` + +// 编写一个函数来查找字符串数组中的最长公共前缀。 + +// 如果不存在公共前缀,返回空字符串 ""。 + +// 输入: + +strs = ["flower","flow","flight"]; + +strs1 = ["dog","racecar","car"]; + +// console.log(strs.sp); + +```javascript +const arr = [90,65,78,66,48,39,92,73];function a1(g){ + + var c = 0; + + const arr1 = []; + + for (var a of g) { + +​ const arr = []; + +​ for (var a of g) { + +​ const b = a.slice('') + +​ arr.push(b[c]); + +​ // console.log(b[c]); + +​ // console.log(c); + +​ } + +​ c++; + +​ // console.log(arr); + +​ var d = 0; + +​ for (var index = 0; index < arr.length-1; index++) { + +​ if (arr[index]==arr[index+1]) { + +​ + +​ }else{ + +​ d = 1; + +​ } + +​ } + +​ if (d==1) { + +​ break; + +​ } + +​ arr1.push(arr[0]); + + } + + if (arr1.length<1) { + +​ console.log('不存在公共前缀'); + + }else{ + +​ console.log('最长公共前缀:'+g[0].substr(0,arr1.length)); + + } + +} + +a1(strs); + +a1(strs1); +``` + +// 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 + +// 输入:l1 = [1,2,4], l2 = [1,3,4] + +// 输出:[1,1,2,3,4,4] + +```javascript +function a2(l1,l2) { + + const arr3 = l1.concat(l2); + + for (var a = 0; a < arr3.length; a++) { + +​ for (var index = 0; index < arr3.length-a; index++) { + +​ if (arr3[index]>arr3[index+1]) { + +​ [arr3[index],arr3[index+1]]=[arr3[index+1],arr3[index]] + +​ } + +​ } + + } + + console.log(arr3); + +} + +const l1 = [1,2,4]; + +const l2 = [1,3,4]; + +a2(l1,l2); +``` + diff --git "a/01\347\277\201\347\253\240\345\275\254/\347\254\224\350\256\260/2022-10-11 .md" "b/01\347\277\201\347\253\240\345\275\254/\347\254\224\350\256\260/2022-10-11 .md" new file mode 100644 index 0000000000000000000000000000000000000000..9d196a2904393578140ae2ab151821a40f547043 --- /dev/null +++ "b/01\347\277\201\347\253\240\345\275\254/\347\254\224\350\256\260/2022-10-11 .md" @@ -0,0 +1,190 @@ +## 数据类型 + +Number - Integer,float + +Boolean,Null,Undefined,Symbol,String + +**字符串转义** + +换行:\n +Tab键:\t + +##### String + +长度:length +大写:toUpperCase() +小写:js.toLowerCase() + +substr(startIndex,counts) +substring(startIndex,endIndex) +startIndex:起始索引位置 +counts:截取字符串的个数 +endIndex:截止索引位置(不包含) + +拆分字符串: split() +去空格: trim() +查看字符串中的元素:includes(),indexof() + +## 数据类型转换 + +#### 将字符串转为整型/浮点型 + +parseInt() /parseFloat() + +Number() + +Plus sign(+) + +## 引用类型 + +#### 数组 + +```javascript +concat:将两个数组合并在一起 +const firstList = [1, 2, 3] +const secondList = [4, 5, 6] +const thirdList = firstList.concat(secondList) +``` + +indexof():查找数组的元素,返回-1表示不存在 +includes() +lastindexof() + +toString():将数组转成字符串 +join():添加指定字符后转成字符串 转成json常用 +slice():切片 +splice():移除,替换元素 + +添加元素:push unshift +删除元素: shift pop + +reverse() :反转 +sort() + +forEach():遍历 +map():遍历 +filter():匹配符合条件的元素 +reduce():汇总数据,返回是一个数据 +every():检查所有数组值是否通过测试 + +## 函数 + +```javascript +function functionName() { +} + +functionName() +``` + +无参无返回 + +```javascript +function square() { + let num = 2 + let sq = num * num + console.log(sq) +} + +square() +``` + +无参有返回 + +```javascript +function printFullName (){ + let firstName = 'Asabeneh' + let lastName = 'Yetayeh' + let space = ' ' + let fullName = firstName + space + lastName + return fullName +} +console.log(printFullName()) +``` + +带1参有返回 + +```javascript +function areaOfCircle(r) { + let area = Math.PI * r * r + return area +} +``` + +带参返回多个值 + +```javascript +function printFullName(firstName, lastName) { + return `${firstName} ${lastName}` +} +console.log(printFullName('Asabeneh', 'Yetayeh')) +``` + +带不确定个参数 + +```javascript +function GetSum() { +// console.log(arguments); +let sum = 0 +for(var i = 0 ; i