Skip to content
Closed

1 #66

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 04 - Array Cardio Day 1/index-SOYAINE.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
// 7. sort Exercise
// Sort the people alphabetically by last name
// 按照姓氏的字母进行排序
const sortName = inventors.sort((a, b) => {
const sortName = people.sort((a, b) => {
return (a.last > b.last) ? 1 : -1;
})
console.table(sortName);
Expand Down
84 changes: 38 additions & 46 deletions 06 - Type Ahead/index-SOYAINE.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,53 @@
<li></li>
</ul>
</form>
<script>
// const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
<script>
// const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';

const endpoint = 'https://gist.githubusercontent.com/soyaine/81399bb2b24ca1bb5313e1985533c640/raw/bdf7df2cbcf70706c4a5e51a7dfb8c933ed78878/TangPoetry.json';
const poetrys = [];


const poetrys = [];
fetch(endpoint)
.then(blob => blob.json())
.then(data => poetrys.push(...data));
function findMatches( wordToMatch, poetrys) {
return poetrys.filter(poet => {
// 正则找出匹配的诗句
const regex = new RegExp(wordToMatch, 'gi');
const author = poet.detail_author.join('');
// console.log(author);
return poet.detail_text.match(regex) || poet.title.match(regex) || author.match(regex);
});
}
.then(blob => blob.json())
.then(data => poetrys.push(...data));

function findMatches(wordToMatch, poetrys) {
return poetrys.filter(poet => {
// 正则找出匹配的诗句
const regex = new RegExp(wordToMatch, 'gi');
const author = poet.detail_author.join('');
// console.log(author);
return poet.detail_text.match(regex) || poet.title.match(regex) || author.match(regex);
});
}

function displayMatches() {
const matches = findMatches(this.value, poetrys);
const regex = new RegExp(this.value, 'gi');
const html = matches.map( poet => {
// 替换高亮的标签
const text = poet.detail_text.replace(regex, `<span class="hl">${ this.value }</span>`);
const title = poet.title.replace(regex, `<span class="hl">${ this.value }</span>`)
// 构造 HTML 值
return `
function displayMatches() {
const matches = findMatches(this.value, poetrys);
const regex = new RegExp(this.value, 'gi');
const html = matches.map(poet => {
// 替换高亮的标签
const text = poet.detail_text.replace(regex, `<span class="hl">${ this.value }</span>`);
const title = poet.title.replace(regex, `<span class="hl">${ this.value }</span>`)
// 构造 HTML 值
return `
<li>
<span class="poet">${ text }</span>
<span class="title">${ title } - ${ poet.detail_author[0] }</span>
</li>
`;
}).join('');
// console.log(html);
suggestions.innerHTML = html;
}

const search = document.querySelector('.search');
const suggestions = document.querySelector('.suggestions');

search.addEventListener('change', displayMatches);
search.addEventListener('keyup', displayMatches);

// console.log(poetrys);
</script>
</body>
</html>





}).join('');
// console.log(html);
suggestions.innerHTML = html;
}

const search = document.querySelector('.search');
const suggestions = document.querySelector('.suggestions');

search.addEventListener('change', displayMatches);
search.addEventListener('keyup', displayMatches);

// console.log(poetrys);
</script>
</body>
</html>
103 changes: 54 additions & 49 deletions 09 - Dev Tools Domination/index-SOYAINE.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<p onClick="makeGreen()">×点×我×呀×</p>

<script>
const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }];
const dogs = [{
name: 'Snickers',
age: 2
}, {
name: 'hugo',
age: 8
}];

function makeGreen() {
const p = document.querySelector('p');
Expand All @@ -18,76 +24,75 @@
}

// Regular
// 常规输出
console.log("我只是 console 世界的一介草民");
// 常规输出
console.log("我只是 console 世界的一介草民");

// Interpolated
// 字符替换
console.log("我的名字叫做 %s ", "log");
console.log("我的年龄是 %f ", 1.23);
// console.log("我的名字叫做 %o ", {1.23: 12});
// 字符替换
console.log("我的名字叫做 %s ", "log");
console.log("我的年龄是 %f ", 1.23);
// console.log("我的名字叫做 %o ", {1.23: 12});

// Styled
// 设定输出的样式
console.log("偷偷告诉你,我会变身 %c ~\(≧▽≦)/~巴拉拉~~", "color: #00fdff; font-size: 2em;");
// 设定输出的样式
console.log("偷偷告诉你,我会变身 %c ~\(≧▽≦)/~巴拉拉~~", "color: #00fdff; font-size: 2em;");

// warning!
console.warn("warning! 我可警告你哦~")
console.warn("warning! 我可警告你哦~")

// Error :|
console.error("error~别又来报错了!╭(╯^╰)╮");
console.error("error~别又来报错了!╭(╯^╰)╮");

// Info
console.info("Talk is cheap. Show me the code");
console.info("Talk is cheap. Show me the code");

// Viewing DOM Elements
// 打印输出 DOM 元素
const p = document.querySelector('p');
console.log(p);
console.dir(p);
// 打印输出 DOM 元素
const p = document.querySelector('p');
console.log(p);
console.dir(p);

// Testing
console.assert(1 ===1, "(这句发布时删除)");
console.assert(1 ===0, "看看看,失策了吧");
console.assert(p.innerHTML.match("她"), "我这儿才没有她这个人");
console.assert(1 === 1, "(这句发布时删除)");
console.assert(1 === 0, "看看看,失策了吧");
console.assert(p.innerHTML.match("她"), "我这儿才没有她这个人");

// clearing
// console.clear();
// console.clear();

// Grouping together
dogs.forEach(dog => {
console.group();
// console.groupCollapsed(); // 收起列表
console.log(`${dog.name}`);
console.log(`${dog.age}`);
console.log(`${dog.name} 有 ${dog.age} 岁了`);
console.groupEnd();
});

//
console.table(dogs);
console.table(dogs, ["age"]);
dogs.forEach(dog => {
console.group();
// console.groupCollapsed();
// 收起列表
console.log(`${dog.name}`);
console.log(`${dog.age}`);
console.log(`${dog.name} 有 ${dog.age} 岁了`);
console.groupEnd();
});

console.table(dogs);
console.table(dogs, ["age"]);

// counting
console.count("(读来过反)羊只");
console.count("(读来过反)羊只");
console.count("(读来过反)鱼条");
console.count("(读来过反)羊只");
console.count("(读来过反)羊只");
console.count("(读来过反)鱼条");
console.count("(读来过反)鱼条");
console.count("(读来过反)羊只");
console.count("(读来过反)羊只");
console.count("(读来过反)羊只");
console.count("(读来过反)鱼条");
console.count("(读来过反)羊只");
console.count("(读来过反)羊只");
console.count("(读来过反)鱼条");
console.count("(读来过反)鱼条");
console.count("(读来过反)羊只");

// timing
console.time('fetch my data');
fetch("https://api.github.com/users/soyaine")
.then(data => data.json())
.then(data => {
console.timeEnd('fetch my data');
console.log(data);
});
// console.timeEnd('fetch my data');

console.time('fetch my data');
fetch("https://api.github.com/users/soyaine")
.then(data => data.json())
.then(data => {
console.timeEnd('fetch my data');
console.log(data);
});
// console.timeEnd('fetch my data');
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions 14 - JavaScript References VS Copying/index-SOYAINE.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
}
};

// console.clear();
// console.log(wes);
// console.clear();
// console.log(wes);

const dev = Object.assign({}, wes);

Expand Down