前端每日一题

小谷之后每天会发布一道常见的笔试面试题,偶尔也会加一些有意思的题目,小伙伴们一边学习一边来检测下自己的学习成果吧~
每天在QQ班级群、“饥人谷前端”微信公众号和本主题同步更新哦~

如何查看答案?

  • 官方答案:关注“饥人谷前端”微信公众号,每天下午18:00之后,进入公众号回复本期题目编号,如:170830,即可查看对应题目的答案哟~
  • 同学答案:每天选择部分谷内同学的答案发布在本主题下。

题号:171027

在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重复的。也不知道每个数字重复几次。请找出数组中任意一个重复的数字。 例如,如果输入长度为7的数组[2,3,1,0,2,5,3],那么对应的输出是第一个重复的数字2。

题号:171026

输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变

ex:

var array = [2,5,6,4,9,8,4,2];

reOrderArray(array);

console.log(array);//[5, 9, 2, 6, 4, 8, 4, 2]


题号:171025

输入一个链表,输出该链表中倒数第k个结点。

题号:171024

我们可以用21的小矩形横着或者竖着去覆盖更大的矩形。请问用n个21的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?

题号:171023

一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。

编号171020

一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法?

编号171019

大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。(n<=39,且n以1开始,不是以0开始的,如1代表斐波那契数列第一项。)

ex:

fibonacci(1);//0
fibonacci(2);//1
fibonacci(3);//1
fibonacci(4);//2
fibonacci(5);//3

编号171018

把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。

ex:

var array=[6501,6828,6963,7036,7422,7674,8146,8468,8704,8717,9170,9359,9719,9895,
           9896,9913,9962,154,293,334,492,1323,1479,1539,1727,1870,1943,2383,2392,
           2996,3282,3812,3903,4465,4605,4665,4772,4828,5142,5437,5448,5668,5706,
           5725,6300,6335];
minNumberInRotateArray(array)//152

编号171017

创建一个函数,实现链表的push(链表尾追加一个node)和pop(链表尾删除一个node),具有pop和push方法的链表,一般称之为堆栈,特点是先进后出。

ex:

//function LinkNode(val){
//  this.val = val;
//  this.next = null;
//}
var head  //这边head是一个链表,值为(1)->(2)->(3)->(4)->(5)->(6);
//node=>val=7
pop(head)//head=>(1)->(2)->(3)->(4)->(5);
push(head,node)//head=>(1)->(2)->(3)->(4)->(5)->(7)

编号171016

创建一个函数,输入一个链表,输出一个数组,数组中的值是链表中的值的逆序输出。
计算机中以1对1方式存数据结构分两种:1.数组 2.链表,如果数据写入和删除操作十分频繁,链表结构优于数组。链表的解释如下:

链表由多个不连续的,独立的节点(LinkNode)链接起来,构成的线性结构。每个节点中最少存在两个属性,一个属性(val)用于保存该节点需要的数据,另一个属性(next),确切说是引用(指针),用于找到下一个节点。
ex:

编号171013

实现一个函数,给定一个数组,返回一个数组内部内容随机打乱的新数组。
ex:

编号171012

实现一个LazyMan,可以按照以下方式调用:

编号171011

在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
ex:

编号171010

实现有一个groupBy函数,把一个集合分组为多个集合,通过 iterator 返回的结果进行分组。
ex:

编号171009

实现一个range函数,range([start], stop, [step]),一个用来创建整数灵活编号的列表的函数,便于each 和 map循环。如果省略start则默认为 0;step 默认为 1.返回一个从start 到stop的整数的列表,用step来增加 (或减少)独占。值得注意的是,如果stop值在start前面(也就是stop值小于start值),那么值域会被认为是零长度,而不是负增长。如果你要一个负数的值域 ,请使用负数step.
ex:

编号170930

利用reduce实现一个main函数,输入一个数组,输出的一个数组,要求如下:
ex:

编号170929

创建一个before函数,调用不超过count 次。 当count已经达到时,最后一个函数调用的结果将被记住并返回。
ex:

编号170928

创建一个compose函数,返回函数集 functions 组合后的复合函数, 也就是一个函数执行完之后把返回的结果再作为参数赋给下一个函数来执行. 以此类推. 在数学里, 把函数 f(), g(), 和 h() 组合起来可以得到复合函数 f(g(h()))。
ex:

编号170927

创建一个after函数, 只有在运行了 count 次之后才有效果. 在处理同组异步请求返回结果时, 如果你要确保同组里所有异步请求完成之后才 执行这个函数, 这将非常有用。
ex:

编号170926

实现一个throttle函数,throttle(function, wait, [options]),创建并返回一个像节流阀一样的函数,当重复调用函数的时候,至少每隔 wait毫秒调用一次该函数。对于想控制一些触发频率较高的事件有帮助。
ex:

编号170925

实现一个debounce函数,debounce(function, wait, [immed返回 function 函数的防反跳版本, 将延迟函数的执行(真正的执行)在函数最后一次调用时刻的 wait 毫秒之后. 对于必须在一些输入(多是一些用户操作)停止到达之后执行的行为有帮助。 例如: 渲染一个Markdown格式的评论预览, 当窗口停止改变大小之后重新计算布局, 等等])
ex:

编号170922

实现一个sortBy(list, iteratee),返回一个排序后的list拷贝副本。如果传递iteratee参数,iteratee将作为list中每个值的排序依据。迭代器也可以是字符串的属性的名称进行排序的(比如 length)。
ex:

编号170921


把如上格式的字符串转换成如下 JSON 对象

编号170920

使用 localStorage封装一个 Storage 对象,达到如下效果:

编号170919

实现一个函数,能够枚举出数组中元素的所有可能的组合。
ex:

编号170918

有两个从小到大已经排序完成的数组,长度分别是n和m,单个数组的不存在重复元素,问如何在m+n次操作下,完成去重,得到一个完整的非重数组。
ex:

编号170915

把冒泡排序(排序结果为从大到小排序)从迭代改写成递归的方式。
迭代的冒泡排序代码如下:

编号170914

实现一个create函数,效果如下:

编号170913

实现一个函数,将浮点数点左边的数每三位添加一个逗号。

编号170912

实现一个bind函数,模拟原生的bind操作符。
ex:

编号170911

实现一个create函数,模拟原生的new操作符。
ex:

编号170908

实现一个parseQuery函数,能够解析location的search字符串(不包括’?’)。
输入一个search,输出一个object,同名参数则是会成为数组。
ex:

编号170907

实现一个invoke函数,invoke(list, methodName, *arguments)
在list的每个元素上执行methodName方法。 任何传递给invoke的额外参数,invoke都会在调用methodName方法的时候传递给它。
ex:

编号170905

实现一个filter函数,模拟原生的filter函数,filter(list, predicate)。
遍历list中的每个值,返回所有通过predicate真值检测的元素所组成的数组。
ex:

编号170904

实现一个find函数,模拟原生的find函数,find(list, predicate)。

在list中逐项查找,返回第一个通过predicate迭代函数真值检测的元素值,如果没有元素通过检测则返回 undefined。 如果找到匹配的元素,函数将立即返回,不会遍历整个list。

ex:

编号170903

编号170902

用CSS实现以下效果:

编号170901

实现一个reduce函数,作用和原生的reduce类似。
reduce(list, iteratee, [memo]),memo是reduce函数的初始值,会被每一次成功调用iteratee函数的返回值所取代 。这个迭代传递4个参数:memo,value 和 迭代的index和最后一个引用的整个 list。如果没有memo传递给reduce的初始调用,iteratee不会被列表中的第一个元素调用。第一个元素将取代memo参数传递给列表中下一个元素调用的iteratee函数。
Ex:var sum = reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);
=> 6

编号170831

纯CSS实现,点击按钮显示一个modal,再点击关闭按钮,关闭modal。示例:

同学答案
答案一:http://jsbin.com/vokiteposa/2/edit?html,css,output
答案二:

答案三:http://jsbin.com/rudunavara/edit?html,output

编号170830

实现一个flatten函数,将一个嵌套多层的数组 array(数组) (嵌套可以是任何层数)转换为只有一层的数组,数组中元素仅基本类型的元素或数组,不存在循环引用的情况。Ex: flatten([1, [2], [3, [[4]]]]) => [1, 2, 3, 4];

同学答案
答案一:

答案二:

答案三:

官方答案
关注“饥人谷前端”微信公众号,每天下午18:00之后,进入公众号回复本期题目编号170830,即可查看对应题目的答案哟~

155 thoughts on “前端每日一题”

  1. Thank you for sharing your info. I really appreciate your efforts and I will be waiting for your further post thank you once again.|

  2. Your style is really unique in comparison to other people I’ve read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this site.|

  3. I am extremely impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one today.|

  4. Its such as you learn my mind! You appear to grasp a lot approximately this, like you wrote the guide in it or something. I believe that you can do with some to drive the message house a bit, however instead of that, this is excellent blog. An excellent read. I’ll definitely be back.|

  5. A fascinating discussion is worth comment. There’s no doubt that that you ought to write more about this topic, it might not be a taboo subject but generally folks don’t discuss these topics. To the next! Cheers!!|

  6. Thank you, I’ve just been looking for info about this subject for ages and yours is the best I’ve found out till now. But, what concerning the conclusion? Are you positive in regards to the source?|

  7. excellent publish, very informative. I’m wondering why the other specialists of this sector do not notice this. You should proceed your writing. I am confident, you’ve a great readers’ base already!|

  8. Good day! Do you know if they make any plugins to safeguard against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?|

  9. Hello there, just became aware of your blog through Google, and found that it is really informative. I’m going to watch out for brussels. I will appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers!|

  10. Magnificent beat ! I wish to apprentice while you amend your website, how can i subscribe for a blog website? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear idea|

  11. Amazing issues here. I am very happy to look your post. Thanks a lot and I’m having a look ahead to touch you. Will you kindly drop me a mail?|

  12. I’ve been exploring for a little for any high-quality articles or blog posts on this sort of space . Exploring in Yahoo I ultimately stumbled upon this web site. Studying this information So i’m glad to show that I have a very good uncanny feeling I came upon exactly what I needed. I most without a doubt will make certain to do not forget this website and provides it a look regularly.|

  13. Thanks for sharing your info. I truly appreciate your efforts and I am waiting for your next write ups thank you once again.|

  14. Have you ever considered about adding a little bit more than just your articles? I mean, what you say is valuable and everything. But think about if you added some great photos or video clips to give your posts more, “pop”! Your content is excellent but with images and clips, this website could certainly be one of the best in its niche. Awesome blog!|

  15. Awesome blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple tweeks would really make my blog jump out. Please let me know where you got your design. Cheers|

  16. constantly i used to read smaller content which also clear their motive, and that is also happening with this post which I am reading at this place.|

  17. Hi this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!|

  18. hello!,I really like your writing so a lot! share we be in contact extra about your post on AOL? I require an expert on this space to solve my problem. May be that’s you! Taking a look ahead to see you. |

  19. Hi, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam feedback? If so how do you prevent it, any plugin or anything you can suggest? I get so much lately it’s driving me mad so any help is very much appreciated.|

  20. I’m not sure exactly why but this weblog is loading incredibly slow for me. Is anyone else having this issue or is it a problem on my end? I’ll check back later on and see if the problem still exists.|

  21. May I simply just say what a relief to find an individual who really knows what they’re talking about online. You actually realize how to bring a problem to light and make it important. A lot more people should check this out and understand this side of your story. I was surprised that you’re not more popular given that you definitely possess the gift.|

  22. Fantastic goods from you, man. I have understand your stuff previous to and you are just too excellent. I really like what you have acquired here, really like what you are stating and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I cant wait to read far more from you. This is really a terrific web site.|

  23. After I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I recieve four emails with the same comment. There has to be an easy method you can remove me from that service? Appreciate it!|

  24. That is very interesting, You are a very professional blogger. I have joined your rss feed and sit up for in quest of extra of your wonderful post. Additionally, I have shared your web site in my social networks|

  25. Good way of describing, and nice article to get information on the topic of my presentation subject matter, which i am going to deliver in college.|

  26. First off I want to say fantastic blog!
    I had a quick question that I’d like to ask if you do not mind.
    I was curious to know how you center yourself and clear your
    head prior to writing. I have had trouble clearing my mind in getting my
    thoughts out there. I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes
    are usually lost simply just trying to figure out how
    to begin. Any ideas or tips? Appreciate it!

  27. Hi there all, here every one is sharing these kinds of familiarity, therefore it’s good to read this blog, and I used to visit this weblog all the time.|

  28. Admiring the time and effort you put into your blog and detailed information you present. It’s great to come across a blog every once in a while that isn’t the same old rehashed information. Excellent read! I’ve bookmarked your site and I’m including your RSS feeds to my Google account.|

  29. Having read this I believed it was rather enlightening. I appreciate you finding the time and energy to put this information together. I once again find myself spending way too much time both reading and leaving comments. But so what, it was still worth it!|

  30. I have been browsing online more than 2 hours today,
    yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my opinion, if all site owners and bloggers made good content as you did, the net will be
    much more useful than ever before.

  31. It’s awesome to pay a visit this site and reading the views of all colleagues on the topic of this post, while I am also zealous of getting knowledge.|

  32. When I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and now whenever a comment is added I receive 4 emails with the exact same comment. There has to be a way you are able to remove me from that service? Thanks a lot!|

  33. Wonderful beat ! I wish to apprentice at the same time as you amend your web site, how could i subscribe for a weblog website? The account helped me a appropriate deal. I have been a little bit familiar of this your broadcast provided vibrant clear idea|

  34. Outstanding post however I was wanting to know if you could write a litte more on this topic? I’d be very grateful if you could elaborate a little bit further. Many thanks!|

  35. I believe that is among the so much important information for me.
    And i am glad studying your article. However should observation on few general
    issues, The website taste is perfect, the articles is in point of fact great : D.
    Good activity, cheers

  36. I’m amazed, I have to admit. Rarely do I come across a blog that’s
    both educative and amusing, and without a doubt, you’ve hit the nail on the
    head. The issue is something that not enough folks are
    speaking intelligently about. I am very happy that I stumbled across this in my search for something relating to this.

  37. First off I would like to say terrific blog! I had a quick question which I’d like
    to ask if you do not mind. I was interested to find out how you center yourself and clear your mind before writing.
    I have had difficulty clearing my thoughts in getting my thoughts out
    there. I do enjoy writing however it just seems like the first 10 to 15
    minutes are usually lost just trying to figure out how to begin. Any recommendations or tips?
    Thank you!

  38. These are really fantastic ideas in on the topic of blogging. You have touched some fastidious factors here. Any way keep up wrinting.|

  39. Wow that was odd. I just wrote an very long comment but after I clicked
    submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyhow, just
    wanted to say wonderful blog!

  40. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?|

  41. Excellent post. I was checking continuously this blog and I’m impressed! Extremely useful information specifically the last part 🙂 I care for such info a lot. I was looking for this particular information for a long time. Thank you and good luck.|

  42. Hey there! I’m at work browsing your blog from my new iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the excellent work!|

  43. Hi there! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My weblog looks weird when viewing from my iphone4. I’m trying to find a theme or plugin that might be able to fix this problem. If you have any suggestions, please share. With thanks!|

  44. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?|

  45. Hello there! I know this is somewhat off topic but I was wondering which blog platform are you using for this website? I’m getting fed up of WordPress because I’ve had problems with hackers and I’m looking at alternatives for another platform. I would be fantastic if you could point me in the direction of a good platform.|

  46. Hello there, just became alert to your blog through Google, and found that it is truly informative. I’m gonna watch out for brussels. I’ll be grateful if you continue this in future. A lot of people will be benefited from your writing. Cheers!|

  47. Hi would you mind stating which blog platform you’re using? I’m planning to start my own blog soon but I’m having a difficult time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S Sorry for getting off-topic but I had to ask!|

  48. Hi! I’ve been reading your blog for a long time now and finally got the courage to go ahead and give you a shout out from Austin Tx! Just wanted to say keep up the excellent work!|

  49. I’m a freshman in college and I was planning on majoring in Computer Engineering, but unfortunately it doesn’t really seem too interesting to me, especially all the computer programming. I’m considering changing my major to Computer Science except I don’t really know what kind of career a degree in Computer Science will get me. So what is the difference between the two? Please help me out, I don’t really have too much time to ask the advisers at my university, so any help would be appreciated..

  50. Hi, I do believe this is a great website. I stumbledupon it 😉 I’m going to come back once again since i have saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide other people.|

  51. I have been surfing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all web owners and bloggers made good content as you did, the web will be much more useful than ever before.|

  52. I’ll right away seize your rss feed as I can not find your email subscription link or e-newsletter service. Do you’ve any? Kindly allow me realize so that I could subscribe. Thanks.|

  53. Hi would you mind stating which blog platform you’re using? I’m planning to start my own blog soon but I’m having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S My apologies for being off-topic but I had to ask!|

  54. It’s perfect time to make some plans for the future and it’s time to be happy. I have read this post and if I could I desire to suggest you few interesting things or advice. Perhaps you can write next articles referring to this article. I want to read more things about it!|

  55. First off I would like to say awesome blog! I had a quick question which I’d like to ask if you don’t mind. I was curious to find out how you center yourself and clear your head before writing. I’ve had difficulty clearing my mind in getting my ideas out. I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes are wasted simply just trying to figure out how to begin. Any ideas or tips? Thank you!|

  56. Does your site have a contact page? I’m having problems locating it but, I’d like to send you an email. I’ve got some suggestions for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it grow over time.|

  57. Thank you for the good writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how can we communicate?|

  58. Woah! I’m really enjoying the template/theme of this site. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appearance. I must say you’ve done a excellent job with this. Additionally, the blog loads extremely fast for me on Firefox. Outstanding Blog!|

  59. Hey just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Firefox. I’m not sure if this is a formatting issue or something to do with browser compatibility but I thought I’d post to let you know. The design look great though! Hope you get the issue fixed soon. Kudos|

  60. Does your site have a contact page? I’m having problems locating it but, I’d like to shoot you an e-mail. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it expand over time.|

  61. It’s appropriate time to make some plans for the future and it is time to be happy. I have read this put up and if I could I desire to suggest you some attention-grabbing issues or advice. Maybe you can write next articles relating to this article. I want to learn more issues about it!|

  62. you’re actually a just right webmaster. The web
    site loading velocity is incredible. It seems that you’re doing any unique trick.

    Furthermore, The contents are masterwork.
    you have done a excellent activity in this topic!

  63. Hi, I do believe this is an excellent website. I stumbledupon it 😉 I may come back once again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.|

  64. As predicted all space coffins and space funeral homes will blow up in space around the year 2080 to year 3000 due to envy. That’s why we need the 777 immortality smart contracts to remind the living to have faith through time. The 777 immortality smart contract is the trust system that can save someone you love through time.

  65. Howdy would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot faster then most. Can you suggest a good hosting provider at a honest price? Kudos, I appreciate it!|

  66. I like the helpful information you provide in your articles.
    I will bookmark your blog and check again here regularly. I am quite
    sure I’ll learn lots of new stuff right here! Best of luck for the next!

  67. Its such as you read my mind! You seem to grasp so much about this, such as you wrote the guide in it or something. I feel that you can do with a few percent to force the message home a bit, however other than that, this is great blog. A fantastic read. I will definitely be back.|

  68. Hi, i believe that i saw you visited my website thus i got here to return the favor?.I am attempting to find issues to improve my web site!I assume its good enough to make use of a few of your ideas!!|

  69. Wow that was odd. I just wrote an extremely long comment but after I clicked submit my comment didn’t appear.
    Grrrr… well I’m not writing all that over again. Anyway, just wanted to say excellent blog!

  70. Generally I do not learn article on blogs, but I wish to say that this write-up very forced me to take a look at and do it! Your writing taste has been surprised me. Thanks, quite nice article.|

发表评论

电子邮件地址不会被公开。