上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页
摘要: 题目是群中小伙伴出的。var a = [1,2,3]; c= a//todo 限制条件 c 不能出现在 = 左边console.log(a)console.log(c)console.log(a === c)在todo中写段代码 执行[][]true我想到的答案1. a.length = 02. 群中其他人的答案 a.splice(0,a.length)想到的错误办法:1. a = [] //因为array是引用类型,a = [] ,只是指向一个新的array,c还是指向老的array2. for(var i = 0 ; i < a.length ; i ++){delete a[i]} 阅读全文
posted @ 2014-02-21 16:38 星堡a 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 代码转自 codewars:http://www.codewars.com/var data = { id: 1, items: [ {id: 2}, {id: 3, items: [ {id: 4}, {id: 5} ]} ]}function extractIds(data){ var arr = []; if(data.id){ arr.push(data.id); } if(data.items){ for(var i in data.items){ var subData = extractIds(data... 阅读全文
posted @ 2014-01-22 18:05 星堡a 阅读(131) 评论(0) 推荐(0) 编辑
摘要: ~~ MY FIRST ASYNC I/O! ~~Write a program that uses a single asynchronous filesystem operationto read a file and print the number of newlines it contains to theconsole (stdout), similar to running `cat file | wc -l`.The full path to the file to read will be provided as the firstcommand-line argument. 阅读全文
posted @ 2013-12-04 18:40 星堡a 阅读(178) 评论(0) 推荐(0) 编辑
摘要: ~~ MY FIRST I/O! ~~Write a program that uses a single synchronous filesystem operation toread a file and print the number of newlines it contains to theconsole (stdout), similar to running `cat file | wc -l`.The full path to the file to read will be provided as the firstcommand-line argument.------- 阅读全文
posted @ 2013-12-04 18:12 星堡a 阅读(215) 评论(0) 推荐(0) 编辑
摘要: ~~ BABY STEPS ~~Write a program that accepts one or more numbers as command-linearguments and prints the sum of those numbers to the console (stdout).----------------------------------------------------------------------HINTS:You can access command-line arguments via the global `process` object.The 阅读全文
posted @ 2013-12-04 16:53 星堡a 阅读(288) 评论(0) 推荐(0) 编辑
摘要: ~~ TIME SERVER ~~Write a TCP time server!Your server should listen to TCP connections on port 8000. For eachconnection you must write the current date & time in the format: YYYY-MM-DD hh:mmfollowed by a newline character. Month, day, hour and minute must bezero-filled to 2 integers. For example: 阅读全文
posted @ 2013-11-20 19:10 星堡a 阅读(227) 评论(0) 推荐(0) 编辑
摘要: ~~ JUGGLING ASYNC ~~其实就是一个循环,在循环里面输出的顺序,和排列后在外面的顺序不一样,这是为什么呢?用第三方async包,直接报错了……This problem is the same as the previous problem (HTTP COLLECT) inthat you need to use `http.get()`. However, this time you will beprovided with three URLs as the first three command-line arguments.You must collect the co 阅读全文
posted @ 2013-11-20 16:38 星堡a 阅读(200) 评论(0) 推荐(0) 编辑
摘要: ~~ HTTP COLLECT ~~Write a program that performs an HTTP GET request to a URL provided toyou as the first command-line argument. Collect all data from theserver (not just the first "data" event) and then write two lines tothe console (stdout).The first line you write should just be an integ 阅读全文
posted @ 2013-11-20 13:16 星堡a 阅读(348) 评论(0) 推荐(0) 编辑
摘要: ~~ HTTP CLIENT ~~Write a program that performs an HTTP GET request to a URL provided toyou as the first command-line argument. Write the String contents ofeach "data" event from the response to a new line on the console(stdout).-------------------------------------------------------------- 阅读全文
posted @ 2013-11-18 21:04 星堡a 阅读(199) 评论(0) 推荐(0) 编辑
摘要: ~~ MAKE IT MODULAR ~~This problem is the same as the previous but introduces the concept ofmodules. You will need to create two files to solve this.Create a program that prints a list of files in a given directory,filtered by the extension of the files. The first argument is thedirectory name and th 阅读全文
posted @ 2013-11-18 17:58 星堡a 阅读(216) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页