
javascript
vulgatecn1
在宁波,有兴趣的人可以面聊
展开
-
回顾一下web
回顾一下web从一个做过GUI角度的人来看一下web 1.GUI布局 GUI的界面是win form,是一个有大小的form,控件是根据坐标放在这个form上的。但web没有这个坐标概念。web是一个stream,而且由于浏览器大小可以改变,所有这些都变了,传统的GUI的控件布局是不变的,除非你代码做了控制,但对于web,元素的位置改变本身浏览器有若干处理,且目前的新的框架bootstraps等原创 2017-11-28 11:55:57 · 228 阅读 · 0 评论 -
array join的技巧
初始化一个数组全部都是一个字母比如aaaaaa用abc=new Array(7).join('a');这里用7,为什么不是6的原因是,join是把7这个字符连接在一起,7个字符之间之间的空档是7-1=6原创 2017-11-17 17:06:35 · 991 阅读 · 0 评论 -
leetcode 40
能解决问题,但效率不咋地/** * @param {number[]} candidates * @param {number} target * @return {number[][]} */var combinationSum = function(candidates, target) { var arrl=[]; arr=[]; candidates原创 2017-10-26 17:33:05 · 259 阅读 · 0 评论 -
leetcode 39
多写代码身体好/** * @param {number[]} candidates * @param {number} target * @return {number[][]} */var combinationSum = function(candidates, target) { var arrl=[]; arr=[];原创 2017-10-26 15:49:36 · 118 阅读 · 0 评论 -
leetcode 93
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2017-10-17 15:53:56 · 208 阅读 · 0 评论 -
leetcode 49
超时,哇哈哈。/** * @param {string[]} strs * @return {string[][]} */var groupAnagrams = function(strs) { arrl = []; if(strs.length==0){ return []; } arrl[0]=[]; arrl[0].原创 2017-11-02 21:58:59 · 135 阅读 · 0 评论 -
leetcode 216
其实还有更加有效率的方法/** * @param {number} k * @param {number} n * @return {number[][]} */var combinationSum3 = function(k, n) { arrl=[]; arr=[]; var search=function(k1){原创 2017-11-02 21:14:33 · 202 阅读 · 0 评论 -
leetcode 120
代码还是写的很水/** * @param {number[][]} triangle * @return {number} */var minimumTotal = function(triangle) { result1=triangle[0].slice(0); result2=result1.slice(0); min=triangl原创 2017-10-25 12:46:28 · 163 阅读 · 0 评论 -
leetcode 119
一如既往的水/** * @param {number} rowIndex * @return {number[]} */var getRow = function(rowIndex) { numRows=rowIndex+1; result1=[1]; result2=result1; if(numRows==0)原创 2017-10-25 11:26:44 · 191 阅读 · 0 评论 -
leetcode 118
我承认这个代码写的很水/** * @param {number} numRows * @return {number[][]} */var generate = function(numRows) { result1=[1]; result2=result1; result=[]; result.push(result1);原创 2017-10-25 11:22:53 · 148 阅读 · 0 评论 -
leetcoder 78
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1],原创 2017-10-16 15:58:39 · 148 阅读 · 0 评论 -
leetcode 77
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:这个题目非常简单,但我做了2-3个小时,我的思路和排名第一的思路是一致的,这里需要注意js需要深度co原创 2017-10-16 13:33:30 · 151 阅读 · 0 评论 -
leetcode 165
我的代码效率居然排100%但看别人的代码我这个代码不够精简。var search1 = function ( version1 ,version2) { pos1 = version1.indexOf('.'); pos2 = version2.indexOf('.'); if(pos1==-1 && pos2==-1){ if(pars原创 2017-11-03 16:51:25 · 234 阅读 · 0 评论 -
leetcode 349
我不怎么满意,实际效率也很低nums1.sort(function (a,b) {return a-b;});nums2.sort(function (a,b) {return a-b;});function unique(nums){ res=[]; hash=[]; for(i=0;ilength;i++){ if(hash[nums[原创 2017-11-03 20:40:52 · 114 阅读 · 0 评论 -
关于学习react之前
在看react的时候,你可以看到super,还包括class之类的,这些都是ES的新特性。这些内容在mozilla上写的还是蛮详细的,建议阅读https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain原创 2017-12-06 20:46:53 · 299 阅读 · 0 评论 -
js的匿名函数定义之后立刻执行
https://en.wikipedia.org/wiki/Immediately-invoked_function_expression这个wiki说的蛮好转载 2017-12-06 09:02:49 · 500 阅读 · 0 评论 -
函数式编程思维
https://book.douban.com/subject/26587213/书在这里 我不怎么喜欢,因为我不想看别的语言是如何描述的 我只想看js怎么做的原创 2017-12-01 21:45:00 · 219 阅读 · 0 评论 -
完美数的判定
最近在看函数式编程其中有一个完美数的定义 对于n 如果他的所有约数和等于n,怎么n是完美数,一行代码var wanmei=function (n){ return [...Array(n-1).keys()].map(i=>i+1).filter(i=>n%i==0).reduce((a,b)=>a+b)==n;}console.log(wanmei(10));原创 2017-12-01 19:37:35 · 631 阅读 · 0 评论 -
三个方法来定义Js类(翻译)
翻译 http://www.phpied.com/3-ways-to-define-a-javascript-class/3 ways to define a JavaScript classSeptember 29th, 2006. Tagged: JavaScript IntroductionJavaScript is a very flexible object-oriented lang翻译 2017-11-16 11:12:01 · 225 阅读 · 0 评论 -
用nodejs到底做什么?
如何解决学了之后无法解决问题的状态?前端的内容很多,有html css javascript三个大模块。但是如何能去解决问题?核心还是根据你的兴趣,或者你根据一个你能看到的实际项目好好研究一下代码。了解其中运作的机制,然后尝试着修改一下代码。js的模式方面的问题只是为了帮助你理解代码,实质上你看了这些东西,对于你一开始写代码没有什么帮助codewar原创 2017-11-20 10:39:57 · 3798 阅读 · 0 评论 -
理解 module.exports和node.js的exports
https://www.sitepoint.com/understanding-module-exports-exports-node-js/What is a Module什么是模块A module encapsulates related code into a single unit of code. When creating a module, this can be interprete翻译 2017-11-19 20:20:33 · 193 阅读 · 0 评论 -
Node.js Modules 模块
模块https://nodejs.org/docs//v9.2.0/api/modules.html Node.js has a simple module loading system. In Node.js, files and modules are in one-to-one correspondence (each file is treated as a separate module翻译 2017-11-19 19:31:08 · 2796 阅读 · 0 评论 -
leetcode 494
这个没有超时,但效率不高/** * @param {number[]} nums * @param {number} S * @return {number} */var findTargetSumWays = function(nums, S) { len1=nums.length; d=[]; d[0]={}; if(nums[0]==0){ d[0][nums[0].toString()]=2; }else {原创 2017-11-04 22:04:44 · 245 阅读 · 0 评论 -
codewar
codewar的js特点是需要熟悉js的新的语言特型,reduce mapleetcode考的算法toWeirdCase("String" );//=> returns "StRiNg"toWeirdCase("Weird string case" );//=> returns "WeIrD StRiNg CaSe"我原创 2017-11-18 19:48:43 · 598 阅读 · 0 评论 -
leetcode 662
做这个题目的人比价少,哇哈哈哈,还是蛮顺利的,效率也不错/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } *//** * @param {Tre原创 2017-11-03 22:12:45 · 322 阅读 · 0 评论 -
leetcode 200
深度优先,仔细仔细仔细var numislands1 = function(grid){ //深度优先 arrl=[]; count=0; n=grid.length; if(n==0){ return 0; } m=grid[0].length; for(var i=0;in;i++) { arr原创 2017-11-01 17:22:10 · 454 阅读 · 0 评论 -
leetcode 125
i=0;j=s.length-1;s=s.toLocaleLowerCase();while(ij){ if(!(s[i].charCodeAt()'z'.charCodeAt() && s[i].charCodeAt()>='a'.charCodeAt() || (s[i].charCodeAt()'9'.charCodeAt() && s[i].charCodeAt()>='0'原创 2017-11-01 16:03:37 · 140 阅读 · 0 评论 -
leetcode 64
https://leetcode.com/problems/minimum-path-sum/description/Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbe原创 2017-10-14 17:09:16 · 168 阅读 · 0 评论 -
leetcode 回文数
判断回文数的问题https://leetcode.com/problems/palindrome-number/description/Determine whether an integer is a palindrome. Do this without extra space.这里注意负数不要判断javascript证书和浮点数是一个数据类型,所以需要用mat原创 2017-10-12 12:07:05 · 273 阅读 · 0 评论 -
leetcode 231
很水 /** * @param {number} n * @return {boolean} */var isPowerOfTwo = function(n) { if(n return false; } if(n==1){ return true; } while(n>1){原创 2017-10-29 13:19:13 · 218 阅读 · 0 评论 -
leetcode 205
/** * @param {string} s * @param {string} t * @return {boolean} */var isIsomorphic = function(s, t) { len_s=s.length; dict1=new Array(); dict2=new Array(); for(var i=0;ilen_s;i++原创 2017-10-29 12:48:46 · 186 阅读 · 0 评论 -
leetcode 204
第一种方法超时,需要的是ln(n)的空间第二种方法是筛选法,需要n的空间var countPrimes1 = function(n) { //最快的方式是一边找素数一遍数数 arr=[2,3]; p=4; count=2; while(p<n){ flag=0; for(var i=0;iarr.lengt原创 2017-10-28 16:13:14 · 152 阅读 · 0 评论 -
leetcode 202
呵呵,这个我第一/** * @param {number} n * @return {boolean} */var isHappy = function(n) { function search(n){ sum=0; while(n>0){ sum+=(n % 10)*(n%10);原创 2017-10-28 15:24:52 · 127 阅读 · 0 评论 -
leetcode题目 1
Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].比较笨的方法,排名比较后面,哈哈哈/** * @param {number[]} nums * @param {number} target * @retur原创 2017-10-11 13:55:23 · 111 阅读 · 0 评论 -
js题目
罗马数字的题目。首先你需要知道罗马数字是怎么来的。具体我这里不说了我后来搜了一下别的答案,有更加好的,你们自己去搜吧,但是我不太确定他这个思路是对的还有类似于我这样查表的,但我这个表好的点在于,扩展性比较好,比如万,亿等等数字都可以在这里扩展,他们的答案是写死的function convert(num) {var arr=[['I','V','X'],['X','L',原创 2017-10-11 10:14:46 · 148 阅读 · 0 评论 -
js题目
写一个电话号码匹配555-555-5555(555)555-5555(555)555-5555555555 555555555555551555 555 5555这里我合并了一些,用了两个正则表达式来匹配var reg1=/^[1]{0,1}[\s]{0,1}\d{3}[\s-]*\d{3}[-\s]*\d{4}$/;原创 2017-10-11 10:12:21 · 361 阅读 · 0 评论 -
leetcode 71
https://leetcode.com/problems/simplify-path/description/第一次拿第一,开心 /** * @param {string} path * @return {string} */ var simplifyPath = function(path) { arr=pa原创 2017-10-18 17:46:40 · 173 阅读 · 0 评论 -
leetcode 73
和排名第一的代码差不多,这个题目不难/** * @param {number[][]} matrix * @return {void} Do not return anything, modify matrix in-place instead. */var setZeroes = function(matrix) { n=matrix.length;原创 2017-10-18 16:28:29 · 184 阅读 · 0 评论 -
leetcode 69
这题简单的,用系统函数,这个是我的代码我排名后面的原因是提交次数太多,sad/** * @param {number} x * @return {number} */var mySqrt = function(x) { return Math.floor(Math.sqrt(x));};原创 2017-10-18 15:54:05 · 242 阅读 · 0 评论 -
leetcode remove-element
https://leetcode.com/problems/remove-element/description/Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space f原创 2017-10-12 15:07:03 · 145 阅读 · 0 评论