diff --git "a/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.10.24.js" "b/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.10.24.js" new file mode 100644 index 0000000000000000000000000000000000000000..5bd7e78bd8d3484a39b9f5b60daeefd3b95d8831 --- /dev/null +++ "b/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.10.24.js" @@ -0,0 +1,168 @@ +const users = { + Alex: { + email: 'alex@alex.com', + skills: ['HTML', 'CSS', 'JavaScript'], + age: 20, + isLoggedIn: false, + points: 30 + }, + Asab: { + email: 'asab@asab.com', + skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'], + age: 25, + isLoggedIn: false, + points: 50 + }, + Brook: { + email: 'daniel@daniel.com', + skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'], + age: 30, + isLoggedIn: true, + points: 50 + }, + Daniel: { + email: 'daniel@alex.com', + skills: ['HTML', 'CSS', 'JavaScript', 'Python'], + age: 20, + isLoggedIn: false, + points: 40 + }, + John: { + email: 'john@john.com', + skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node.js'], + age: 20, + isLoggedIn: true, + points: 50 + }, + Thomas: { + email: 'thomas@thomas.com', + skills: ['HTML', 'CSS', 'JavaScript', 'React'], + age: 20, + isLoggedIn: false, + points: 40 + }, + Paul: { + email: 'paul@paul.com', + skills: ['HTML', 'CSS', 'JavaScript', 'MongoDB', 'Express', 'React', 'Node'], + age: 20, + isLoggedIn: false, + points: 40 + } + } +// 1.统计在线人数 + const arr1 =Object.values(users) + var sum=0 + for (let index = 0; index < arr1.length; index++) { + if (arr1[index].isLoggedIn==true) { + sum++ + } + } + console.log(sum); + +// for(let name in users){ +// if (users[name].isLoggedIn==true) { +// sum++ +// } +// } + + sum=0 +// 2.统计分数大于50的人数 +for(let name in users){ + if (users[name].points>50) { + sum++ + } +} +console.log(sum); +// 3.查找会MongoDB的人,并打印其名字 +const arr =Object.keys(users) +for (let index = 0; index < arr1.length; index++) { + var a= arr1[index].skills.indexOf('MongoDB') + if (a!=-1) { + console.log(arr[index]); + } + } +// for(let name in users){ + +// var a= users[name].skills.indexOf('MongoDB') +// if (a!=-1) { +// console.log(name); +// } +// } +// 4.查找同时会:MongoDB, Express,React,和Node 的人,并打印其名字 +for(let name in users){ + + var a= users[name].skills.indexOf('MongoDB') + var b= users[name].skills.indexOf('Express') + var c= users[name].skills.indexOf('React') + var d= users[name].skills.indexOf('Node'); + if (a!=-1&&b!=-1&&c!=-1&&d!=-1) { + console.log(name); + } +} +var collection = { + "1275":{ + "album":"依然范特西", + "artist":"周杰伦", + "tracks":[ + "听妈妈的话", + "千里之外" + ] +}, + "2468":{ + "album":"西界", + "artist":"林俊杰", + "tracks":[ + "西界", + "杀手" + ] +}, + "3245":{ + "artist":"许嵩", + "tracks":[ ] + }, + "5439":{ + "album":"遇见" + } +} + +// 1.定义方法更新记录: +// function updateRecords(id,prop,value) +// 要求: +// 1).如果传入的value是一个空值,表示将该属性删除 +// 2).传入的prop如果是tracks,则代表添加,其他是修改 + const arrC = Object.keys(collection); +function updateRecords(id,prop,value){ + + arrC.forEach(num=>{ + if (id==num) { + console.log(collection[num]); + if (prop=='tracks') { + + if (value=='') { + collection[num].tracks.splice(0,collection[num].tracks.length); + }else{ + collection[num].tracks.push(value); + } + }else{ + collection[num][prop]=value; + // if (prop=='artist') { + // collection[num][prop]=value + // const Change={artist:value} + // collection[num]=Object.assign(Change,collection[num]) + // } + } + } + }) + +} + +updateRecords(3245,'tracks','有何不可') +updateRecords(3245,'tracks','') +updateRecords(5439,'artist','孙燕姿') +updateRecords(5439,'album','逆光') +console.log(collection); + +// 3245 tracks '有何不可' +// 3245 tracks '' -->删 +// 5439 artist '孙燕姿' +// 5439 album '逆光' \ No newline at end of file diff --git "a/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.10.26.js" "b/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.10.26.js" new file mode 100644 index 0000000000000000000000000000000000000000..bfe589ab120e8a2a23e7820bb325f121c44754e4 --- /dev/null +++ "b/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.10.26.js" @@ -0,0 +1,24 @@ +var num ='500050' +const arr = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'] +const arr1 = ['','十', '百', '千', '万', '十', '百', '千', '亿', '十'] +const numarr=num.split('').reverse() +var newNum='' +const strArr=[] + numarr.forEach((m,n)=>{ + strArr.unshift(m==0?arr[m]:arr[m]+arr1[n]) + + }) + console.log(strArr); + for (let m = 0; m < strArr.length; m++) { + for (let n = 0; n < strArr.length; n++) { + if (strArr[n]=='零'&&strArr[m-n]=='零') { + strArr.splice(n,1) + console.log(strArr); + } + if (strArr[strArr.length-1]=='零') { + strArr.pop() + } + } + } + console.log(strArr); + \ No newline at end of file diff --git "a/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/Test.html" "b/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/Test.html" index efe8e544fd0c0e4fbb3fa2e58cce83e87ededc98..b182ccd57ebeeead7d2074040627d0e4cb98447a 100644 --- "a/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/Test.html" +++ "b/10\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/Test.html" @@ -5,7 +5,7 @@