Jerry Blog

Your world should be a lively experience, not a series of hearsays.

【One topic per day】Sum of the first nth term of Series

前端题库,Javascript题集

Sum of the first nth term of Series Task: Your task is to write a function which returns the sum of following series upto nth term(parameter). Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +... Rule...

【One topic per day】The Supermarket Queue

前端题库,Javascript题集

The Supermarket Queue There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out! The f...

【One topic per day】Which are in?

前端题库,Javascript题集

Which are in? Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2. #Example 1: a1 = [“arp”, “live”, ...

【One topic per day】Delete occurrences of an element if it occurs more than n times?

前端题库,Javascript题集

Delete occurrences of an element if it occurs more than n times Enough is enough! Alice and Bob were on a holiday. Both of them took many pictures of the places they’ve been, and now they want to ...

一个在线实时预览代码编辑器的实现

基于CodeMirror

在线代码编辑器–Html/Markdown支持 作为开发者,经常会使用各式编辑器,一个体验良好的编辑器会给使用者舒适的coding体验。 但当我们不是使用自己熟悉的电脑,在任意的环境下,我们就需要有一个在线的编辑器进行coding。事实上已经有太多优秀的online编辑器(jsbin/jsfiddle等)。笔者也根据自己的工作需求,做了一个简介版的编辑器,用于Html以及Markdown的开...

node针对文件以及文件夹的相关操作

基于一个需求引发的一篇node文件基础操作笔记

需求来源 后端团队写了一套服务端的API文档,但由于技术选型上的原因,产生了如下结构: - demo/ + img/ # 文档图片目录 index.html # 总文档 app.html # 子文档1 bean.html # 子文档2 f...

利用postMessage解决iframe跨域通信

推荐两种实现方式,一为同域的页面代理,二为postMessage

前言 作为前端,我们经常会接触到的一种页面嵌套式形态就是iframe,而针对iframe最常见的需求点就是需要高度自适应,要解决这个问题,就必须使得父子页面之间可以进行通信。由于同源策略影响,跨域通信是最为棘手的存在。 目前有两种比较通用的方法可以支持。 方法一 页面A:http://www.a.com/iframe/a.html 页面B:http://www.a.com/iframe/...

阻止嵌套滚动条的外层滚动行为

利用js的方法阻止document层的滚动条行为

需求描述 在页面中的div模块出现滚动条的时候,操作当前div的滚动条时,外部document的滚动条保持禁止。 实现原理 设置开关,默认开启document的滚动条 当鼠标移入到目标模块时候记录当前的document的scrollTop,关闭开关 当鼠标移出目标模块开启开关 window.onscroll判断开关是否开启,当开关关闭的时候,scrollTop恒设置为被记...

【笔记】搭建React服务端渲染环境

基于node,前后端分离,前端同构,前后端路由匹配

前言 上个月公司进行官网改版,考虑需要seo,故无法使用纯单页模式,早期工作模式是前端提供静态页面,后端工作人员来套模版,但会导致代码不同步,且每一次的改动增加双方的改动量。也因为Jquery这种比较老的模式如今也被MVVM锁代替,因此打算直接上node来支撑前端服务去调用后端的restfulAPI,本文将着重讲解React服务端渲染( Server-Side Rendering )搭建要点...

【算法题】随机生成指定长度的字符串

前端面试题/算法题

常见算法面试题之一!!! 随机生成指定长度的字符串 解题要点: 随机字符串的范围为26个英文字母和10个数字 随机数取值范围是:Math.random()乘以总数减1(charAt从0开始) 字符串长度即为循环次数 const randomString = n => { let str = 'abcdefghijklmnopqrstuvwxyz012345678...