node.js内容管理系统

node-CMS

由node.js书写企业内容管理系统

来源

由我和 JxJayden 共同开发的企业内容管理系统。此版本移除了七牛云密钥及加密密钥,并以 .demo.js做结尾。

源码

node-CMS

几种排序算法的javascript实现

排序算法

之前有用php总结过几个排序算法,也用js实现过,但是demo早就消失不见,刚好有题目是用js写一种排序算法,我就吧几种算法总结下。

冒泡排序

冒泡排序简单来说就是把最大的冒泡出来,时间复杂度 O(n^2),最简单是 O(n)

ES6-calss 以及理解原型链

Class

在ES6中,引入了Class,可以很方便的来定义类。例如

1
2
3
4
5
6
7
8
9
class A {
constructor(x,y){
this.x=x;
this.y=y;
}
toString(){
return this.x+this.y;
}
}

事实上ES6的class只是一个语法糖。上述代码等同于:

1
2
3
4
5
6
7
function AA(x,y){
this.x=x;
this.y=y;
}
AA.prototype.toString=function(){
return this.x+this.y;
}

所以 在实例化后

node.js 操作 mongodb 以及 mongoose 使用

node.js 操作 mongodb

首先引入 mongodb,然后打开数据库xxx,之后进入mycoll 集合。

generator-promise

generator 函数和 promise 对象的结合使用

当使用generator函数进行“流程管理”或使用koajs时候,往往需要使用异步操作。

angularjs 全局非阻塞消息通知

目的

因为我的一个angularjs fruit-angular 项目要用的关系,而我又不想用bootstrap或者什么消息通知库之类,所以自己写了个。

预览

重制果儿岛商城By AngularJS

前言

本项目全部采用果儿岛提供的api,其中省略了支付宝付款这个功能,即不能替代原本官方商城进行商品支付。
使用了angular1.5.8 使用bower管理依赖。采用 rem 实现自适应。以及css media query控制实现响应式布局。部分页面使用flex布局。

源码

github

Demo

http://fruit.garychang.cn

新窗口打开

使用

1
2
3
4
5
6

git clone

bower install

npm install

2016年阿里秋季校招前端题

吐槽

首先这个博文不是内容不是全部的前端题目,而只是我考的其中一道题,每个人的题目也不一样,写这个文章是自我安慰下昨天答错的题,尽管也没什么用了。

不过不得不说,阿里题目出的比京东强多了,但是编程题不能离开浏览器用本地编辑器也是很不爽的,但是我还是切出来用编辑器了。从今年秋季内推面试挂了到昨天笔试不理想,我想我的校招阿里之路也再见了。

题目

题目是大概这样的:
定义个查找方法和排序方法来查找数据,没有规定 .orderBy() 或者 where() 是不是可选的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

var data = [
{ userId: 8, title: 'title1' },
{ userId: 11, title: 'other' },
{ userId: 15, title: null },
{ userId: 19, title: 'title2' }
];

var find = function(origin){
//your code are here...
}

//查找data中,符合条件的数据,并进行排序
var result = find(data).where({"title": /\d$/}).orderBy('userId', 'desc');
console.log(result);
// 返回值
// [{ userId: 19, title: 'title2'}, { userId: 8, title: 'title1' }];

解答

方法很简单,在 find 函数中定义个构造函数并返回其实例。给这个构造函数添加方法就行。没有用到原型链什么的,当时想多了 :-(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

var find = function(data) {
function A(data) {
this.$data = [];
var $this=this;
this.where = function(where) {
data.forEach(function(e) {
for (var key in where) {
if (where[key] instanceof RegExp) {
if (where[key].test(e[key])) {
$this.$data.push(e);
}
} else if (where[key] == e[key]) {
$this.$data.push(e);
}
}
});
return this;
};
this.orderBy=function(id,order){
this.$data.sort(function(a,b){
if(order="desc"){
return b[id]-a[id];
}
});
return this.$data;
}
};
return new A(data);
}
var result = find(data).where({ "title": /\d$/ }).orderBy('userId', 'desc');
console.log(result);
//[ { userId: 19, title: 'title2' },
// { userId: 8, title: 'title1' } ]

用javascript生成回型矩阵 蛇形矩阵

回型/蛇形矩阵形式

1
2
3
4

1 2 3
8 9 4
7 6 5

上述这种形式即为蛇形矩阵。

ES6-Map

ES6引入Map的目的

js 的对象本质上就是键值对集合也就是 Hash结构,但是只能用字符串作为键值,而 Map 就可以解决这个问题。

用法

1
2
3
4
5
6
7
8
9
10
11
12

var m= new Map();
var o={
a:1
};

m.set(o,"123");
m.get(o); // "123"

m.has(o); // true
m.delete(o); // true
m.has(o); // false
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×