yoluxi / daily Goto Github PK
View Code? Open in Web Editor NEWdaily
License: MIT License
daily
License: MIT License
函数定义的两种方式
1 表达式
const a = function() {
}
// 使用场景 递归 在堆栈跟踪函数
const a = function a() {
}
2 声明式
function a() {
}
递归函数就是使用了函数堆栈
闭包:
可以使内部函数的使用更安全
notice
如果内部函数跟外部函数使用同样的变量名 内部函数则无法访问到外部的变量
给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。
此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。
不能使用代码库中的排序函数来解决这道题。
输入: [2,0,2,1,1,0]
输出: [0,0,1,1,2,2]
通过函数包装后返回的功能增强的组件
const EnhancedComponent = higherOrderComponent(WrappedComponent);
Redux的conect
mixins用来做什么
给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度。
不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素
示例 :
给定 nums = [3,2,2,3], val = 3,
函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2。
你不需要考虑数组中超出新长度后面的元素。
给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度。
不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
示例
给定 nums = [0,0,1,1,1,1,2,3,3],
函数应返回新长度 length = 7, 并且原数组的前五个元素被修改为 0, 0, 1, 1, 2, 3, 3 。
你不需要考虑数组中超出新长度后面的元素。
给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。
不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
示例 :
给定 nums = [0,0,1,1,1,2,2,3,3,4],
函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。
你不需要考虑数组中超出新长度后面的元素。
优点:
1 降低的可变的复杂度
2 节省内存空间 不修改的属性共享 修改的属性隔离
3 便于处理undo/redo
4 fp
缺点:
1 与原生对象易混淆
给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
输入: [0,1,0,3,12] 输出: [1,3,12,0,0]
function bubbleSort(arr) {
console.time('冒泡排序耗时');
var temp = 0
for (var i = 0; i < arr.length - 1; i++) {
let sortable = true
for (var j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j+1]) {
temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
sortable = false
}
}
if (sortable) {
break
}
}
console.timeEnd('冒泡排序耗时');
return arr
}
function insertSort(arr) {
console.time('直接插入排序')
let current = 0
let prevIndex = 0
for ( var i = 0; i < arr.length; i++ ) {
current = arr[i]
prevIndex = i - 1
while(prevIndex >= 0 && arr[prevIndex] > current ) {
arr[prevIndex + 1] = arr[prevIndex]
prevIndex--
}
if (prevIndex + 1 != i) {
arr[prevIndex + 1] = current
}
}
console.timeEnd('直接插入排序')
return arr
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.