更改后的main
/**
* Created by lenovo on 2017/5/18.
*/
var test=function(){
};
test.prototype.sort=function(words) {
var res = [];
var p;
var s=words;
var ary = s.split(' ');
ary.sort();
if(words == '')
{
return "";
}
else
{
for(var i = 0;i<ary.length;)
{
var count = 0;
for(var j=i;j<ary.length;j++)
{
if(ary[i] == ary[j])
{
count++;
}
}
res.push([ary[i],count]);
i+=count;
}
//res 二维数维中保存了 值和值的重复数
for(var x=0;x<res.length;x++) {
for (var i = x; i < res.length; i++) {
if (res[x][1] < res[i][1]) {
var max=res[i];
for (j = x; j < i; i--) {
res[i] = res[i - 1];
}
res[x] = max;
}
}
}
for(var i=0;i<res.length;i++)
{
console.log(res[i][0]+" "+res[i][1]+"\r\n");
//document.writeln(res[i][0]+" "+res[i][1]+"<br/>");
}
}
}
module.exports = test;
测试代码
/**
* Created by lenovo on 2017/5/18.
*/
var test = require("../lib/main");
describe("FrequencyN", function () {
it("should return equal", function () {
var result = new test();
//noinspection JSUnresolvedFunction
expect(result.sort("")).toEqual("");
});
it("should return one word one number", function () {
var result = new test();
//noinspection JSUnresolvedFunction
expect(result.sort("he")).toEqual("he 1");
});
it("should return one word one number", function () {
var result = new test();
//noinspection JSUnresolvedFunction
expect(result.sort("he is")).toEqual("he 1\r\nis 1");
});
it("should return one word one number", function () {
var result = new test();
//noinspection JSUnresolvedFunction
expect(result.sort("he is is")).toEqual("is 2\r\nhe 1");
})
it("should return one word one number", function () {
var result = new test();
//noinspection JSUnresolvedFunction
expect(result.sort("it was the age of wisdom it was the age of foolishness it is")).toEqual(
"it 3\r\nwas 2\r\nthe 2\r\nage 2\r\nof 2\r\nwisdom 1\r\nfoolishness 1\r\nis 1");
});
});
Git练习
![7SVLED@8Z}UD]YRVRHB0P(O.png](http://upload-images.jianshu.io/upload_images/5439747-e0b7eda6f4c6911e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![VK]@ZU8ZH03}4N8}]1~JFAH.png](http://upload-images.jianshu.io/upload_images/5439747-589aed8fc04dd1a1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![LEJ66P6]LB@Y%RZPCTZ5`(Q.png](http://upload-images.jianshu.io/upload_images/5439747-c0d68681ba6882d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Git上传到远程仓库
![)BY]4OB(5BGSYTH8Z1_{1}2.png](http://upload-images.jianshu.io/upload_images/5439747-ae687e82b1a2c0fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)