- 博客(194)
- 资源 (1)
- 收藏
- 关注
原创 sumOf的柯里化函数
满足 sum(1, 2, 3, 4).sumOf() 输出 10满足 sum(1)(2, 3, 4).sumOf() 输出 10满足 sum(1)(2)(3, 4).sumOf() 输出 10满足 sum(1)(2)(3)(4).sumOf() 输出 10function sum(...args) { const num = args.reduce((p, c) => p + c, 0) const fn = (...args) => { return sum.
2021-01-13 19:54:50
1015
原创 求数组的深度
function getArrayDepth(arr) { const depths = [] arr.forEach( ele => { let depth = 0 if (Array.isArray(ele)) { depth = getArrayDepth(ele) } depths.push(depth) }) retur...
2020-02-10 19:18:36
1598
原创 async await实践
现在有这样一个需求,有四个请求同时发出,如果有某个出错了,如果总次数少于10次,我就重新请求let num = 0;let res = void 0;function reqs() { let pro1 = new Promise((res, rej) => { res(fetch('http://localhost:8080')); }); let pro2...
2019-10-29 17:22:02
329
原创 从一段代码讲讲我理解的事件循环机制
setTimeout(function () { console.log('8')}, 0)async function async1() { console.log('1') const data = await async2() console.log('6') return data}async function async2() { return ne...
2019-10-21 21:54:05
221
原创 css属性选择器
css属性选择器类型类型[attr] 选择含有attr属性的元素[attr=value] 选择含有attr属性,并且值为value的元素,这里要注意的是,value可以放在双引号里,就像这样 [attr=“value”],如果遇到下面这种情况,为了选中元素,就要使用加双引号的写法了 <div title="test test1"></div> <s...
2019-09-24 21:19:32
295
原创 最小栈和最小队列
// 最小栈// 思路:开两个栈,一个用来存储数据,另一个存储最小值的下标function MinStack(): any{ let a = [], b = [] return (function(){ return { name: 'zafu', push: function (val: number): void { let le...
2019-07-21 18:50:44
547
原创 安卓线程通信方式的两种方式
package cn.tedu.progress;import android.os.Handler;import android.os.Message;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.wi...
2019-07-06 13:03:15
217
原创 class field所带来的一些问题
public field 和private field组成了class field,这篇文章不讲private field ,只谈public field所带来的问题我会根据例子来讲解,这样会更好理解一些class SafeUser { constructor() { this.password = '1234' }}上面代码非常简单,就是声明了一个...
2019-06-23 19:49:32
2314
原创 resize函数防抖和节流写法
// 防抖function debounce(operate, delay) { let time = null let timer = null let newTime = null function task() { newTime = +new Date() if(newTime - time < delay){ ...
2019-06-13 14:58:52
3969
原创 不同窗口通信的postMessage方法的详解
窗口之间的通信,如果是不同域的,会受到浏览器的同源策略的限制,这篇文章介绍的postMessage方法可以解决这个问题postMessage是window的属性,一般用于跨域窗口之间的通信我们直接从实例中来学这个方法, 这样会理解的更深我们现在要实现https://v.qq.com/和https://ke.qq.com之间的通信在v.qq.com的控制台中输入下面代码,打开ke....
2019-06-12 23:46:24
4021
原创 storage事件,实现同一页面多tab时的状态同步
设想一个场景,我们打开多个淘宝的页面,在其中一个页面进行了添加商品的操作,商品数量更新,但怎么让其它页面和它保持同步呢?这篇博客来讲一下storage事件storage事件负责监听localStorage的变化,当然只有同域下localStorage发生变化才会触发该事件我们来试一下// 注册storage事件function event(ev) { console.lo...
2019-05-28 12:00:28
973
原创 设置X-Frame-Options首部防止点击劫持
一.前沿我们来浏览页面的时候,经常会遇到这种情况:点击链接xxx,打开的却是xxx(另一个网站)这种现象我们称之为点击劫持(clickjacking)上面的描述比较简短,我们来看下点击劫持的定义:点击劫持(ClickJacking)是一种视觉上的欺骗手段。大概有两种方式,一是攻击者使用一个透明的iframe,覆盖在一个网页上,然后诱使用户在该页面上进行操作,此时用户将在不知情的情况...
2019-05-11 18:23:38
4374
原创 快手笔试编程题-最多能去到多少个方块
题目大意:输入k, m, nk表示一个阈值,如果行和列每个位上的数字之和大于k,这个格子就不能去,求最多能去的格子数题目不难,但由于时间还有15分钟才看这题,加上紧张的因素,没写出来,难受呀!广搜或者深搜都可以,我用的是广搜function getAnswer(k, n, m) { let ju = [] for(let i = 0; i < m; i ++) {...
2019-03-31 15:00:49
460
原创 二叉树的前序,中序,后序遍历
今天在做快手的笔试题,其中有道就我们判断一个满二叉树是否是平衡二叉树的问题,什么是平衡二叉树呢,就是为空树,或者左子树的所有值小于根节点,右子树所有值都大于根节点思路:按中序遍历一遍二叉树,看是否升序,如果是就是平衡二叉树,否则就不是binary_tree是每层按顺序输入的二叉树节点的值,是个数组// 前序遍历 function proRes(binary_tree, index)...
2019-03-30 23:19:47
387
原创 node代理跨域获取图片
我们知道,img标签是不会有跨域的问题的,所以我们可以直接在img标签中利用src属性引用其它域中的图片,但是如果出现下面的情况呢?<img src="http://pics6.baidu.com/feed/5bafa40f4bfbfbed9f8a1ef376c06332aec31f1a.jpeg?token=7de2efd6c5a751773e7b13a244a38d3f&s...
2019-03-27 16:15:12
1608
1
原创 跨域实践之jsonp实现跨域
jsonp实现跨域是一种十分普遍的方法,它利用的是script标签里的src属性可以跨域请求的功能来实现跨域,那这篇博客就来实践一下jsonp这种方法既然要跨域,那我们先来看下不用jsonp,直接请求的结果 let xhr = new XMLHttpRequest() let getDate = (data) =>{ conso...
2019-03-19 18:51:59
254
原创 跨域实践之node代理获取Json数据
在不会服务端代理之前,遇到返回Json格式数据url,是一点办法都没有,因为jsonp用不了,比如下面的数据接口(jsonp的具体用法看我的另一篇博客https://blog.youkuaiyun.com/dreamjay1997/article/details/88669493)其中大部分都是返回json格式的数据的,除了joke0可以用jsonp实现跨域的数据获取,所以一旦没有了服务...
2019-03-19 18:12:01
604
原创 997. Find the Town Judge
In a town, there areNpeople labelled from1toN. There is a rumor that one of these people is secretly the town judge.If thetown judge exists, then:The town judge trusts nobody. Everybody (e...
2019-02-24 13:32:23
326
原创 node 小爬虫
const express = require('express')// cheerio相当于服务器端的jQueryconst cheerio = require('cheerio')// superagent 是一个http请求库,我们利用它来获取页面内容const superagent = require('superagent')let app = express()a...
2019-02-23 21:44:16
178
原创 Objects are not valid as a React child
自己写一个简单的React组件的时候,因为Objects are not valid as a React child (found: Sat Feb 23 2019 16:18:01 GMT+0800 (China Standard Time)). If you meant to render a collection of children, use an array instead....
2019-02-23 16:25:25
4786
1
原创 72. Edit Distance
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a character Delete a chara...
2019-02-21 16:00:42
135
原创 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizesthe sum of all numbers along its path.Note: You can only move either down or right at an...
2019-02-20 18:11:41
121
原创 65. Valid Number
Validate if a given string can be interpreted as a decimal number.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true" -90e3 "
2019-02-19 20:44:48
134
原创 67. Add Binary
Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100"Exam...
2019-02-19 11:38:48
128
原创 57. Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Examp...
2019-02-19 10:59:13
146
原创 59. Spiral Matrix II
这道题和另一道题目54. Spiral Matrix,很相似,我觉得会了那道题,这题是很简单的,下面是那题的博客链接https://blog.youkuaiyun.com/dreamjay1997/article/details/87437861Given a positive integer n, generate a square matrix filled with elements from ...
2019-02-18 13:08:29
203
原创 66. Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element...
2019-02-17 14:12:59
244
原创 56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...
2019-02-16 18:39:37
260
原创 54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]...
2019-02-16 11:45:07
145
原创 32. Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid...
2019-02-13 12:50:37
215
原创 42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented by array...
2019-02-12 14:33:37
149
原创 16. 3Sum Closest
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...
2019-02-11 12:24:32
143
原创 989. Add to Array-Form of Integer
For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1].Given the array-form A of a non-negati...
2019-02-10 23:00:33
199
原创 react路由match.path和match.url的区别
match.path指的是返回当前组件所对应的pathmatch.url指的是当前组件真实的url如果还有些模糊,看下面的例子就明白了import React from "react";import { BrowserRouter as Router, Route, Link } from "react-router-dom";const App = () => ( ...
2019-02-03 14:25:49
4631
原创 python 读写txt文件乱码问题
从报错讲起:UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 2: illegal multibyte sequence出现这个错误一般是由于打开文件时,没有指定编码引起的,比如下面代码with open('../corpus.txt', mode = 'r') as f:解决方法很简单,为其指定...
2019-01-31 11:14:35
16441
1
原创 String Without AAA or BBB
Given two integers A and B, return any string S such that:S has length A + B and contains exactly A 'a' letters, and exactly B 'b' letters; The substring 'aaa' does not occur in S; The substring '...
2019-01-27 13:23:13
302
原创 /\s+/g和/\s/g的区别
正则表达式/\s+/g和/\s/g,目的均是找出目标字符串中的所有空白字符,但两者到底有什么区别呢?我们先来看下面一个例子:let name = 'ye wen jun';let ans = name.replace(/\s/g, ''); // 'yewenjun'let ans2 = name.replace(/\s+/g, ''); // 'yewenjun'从上...
2019-01-22 18:47:57
16450
原创 一道骚气的js题
function a(xx) {this.x = xx; return this}var x = a(5);var y = a(6);console.log(x.x);console.log(y.x);直切主题,看上面的代码,最后的输出是什么?先不急,我们一步一步分析:首先预编译的环节之后:x=undefined, y = undefined, a = function...
2018-12-30 14:18:54
544
2
原创 node文件操作
一.文件读取分为同步的读和异步的读1.fs.readFileSync 同步读取var fs = require('fs');var data;try{ data = fs.readFileSync('./content.txt', 'utf8'); console.log('content: ', data);}catch(err) { console.l...
2018-12-25 09:53:43
179
原创 React 的key详解
我们在学React的list章节的时候,一定会提到key这个属性,key是给React用的,主要是为了区分不同的组件,是组件的唯一标识,当我们没用设置key属性的时候,React会给出警告,并且会把数组的index作为组件的key值,所以说key对于组件是必不可少的,那有同学可能会问了,如果key这么重要的话,为什么我只在用数组的map方法返回的组件中用过key,其它组件我却没有用过,其实对于其它...
2018-12-24 20:11:23
1105
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人