您的位置:首页 > Web前端 > JavaScript

ThoughtWorks西邮暑期特训营--JavaScript在线笔试题

2016-06-28 20:37 766 查看
ThoughtWorks 公司在西邮正式开办的只教女生前端开发的女子卓越实验室已经几个月过去了,这次计划于暑期在西邮内部开展面向所有性别所有专业的前端培训。

具体官方安排请戳:ThoughtWorks 西安邮电大学暑期特训营(2016)

不知为期7-18至8-26六周、每周6天、每天8小时的训练后,我这个本学PHP走服务端的Someone前端能力会有多么厉害,期待ING。

这篇博客把自己当时摘抄的 ThoughtWorks 在线 JavaScript 笔试题和自己相应的解答代码从笔记中整理出来,遗憾的是当时没有多截图。

补充一句,我是男生。这次培训名单的九十七分之十七的男生之一。

(下面有彩蛋,下面有彩蛋,下面有彩蛋。)

第一题

第一题只需要在 GitHub 上新建一个仓库并使里面包含小写的 readme.md 即可。

最终将该题目的 GitHub 地址填写到提交栏里,网站后台会自动拖拽仓库并检验答案(用到了 jasmine ,自己并不太了解),后面所有题提交步骤与此相同。

下面是能用到的简单的 git 命令。具体 GIT 教程可参考简单易懂的:git-简明指南

git init


git clone *


rm -rf .git


git remote add origin *


git add *


git commit -m "*"


git push *


第二题

题目描述
写一个函数,使该函数满足如下要求:
输入&&输出:
当输入数据格式为 100 输出为 100
当输入数据格式为 1000 输出为 1,000
当输入数据格式为 1000000 输出为 1,000,000
当输入数据格式为 1000.0 输出为 1,000
当输入数据格式为 100.2342 输出为 100.2342
NOTE:请注意数据格式

'use strict';

function thousands_separators(num) {
var parts;
if (!isNaN(parseFloat(num)) && isFinite(num)) {
num = Number(num);
num = num.toString();
parts = num.split('.');
parts[0] = parts[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + (','));
return parts.join('.');
}
}

module.exports = thousands_separators;


第三题

题目描述
写一个函数,使该函数返回输入数组中所有第偶数个元素的中位数:
输入&&输出:
当输入数据为 [1,2,3,4]时 输出为 3
NOTE:请注意数据格式

'use strict';

function calculate_median(arr) {
var eventimes=0;
for(var i = 1; i < arr.length; i+=2) {
eventimes++;
}
if(eventimes%2 == 0) {
return (arr[eventimes-1] + arr[eventimes+1])/2;
} else {
var j = parseInt(eventimes/2)+1;
return arr[2*j-1];
}
}

module.exports = calculate_median;


第四题

题目描述
实现src/collect_all_even.js中的collect_same_elements函数,使该函数满足如下要求:
选出A集合中元素的key属性,跟B对象中value属性中的元素相同的元素
输入&&输出:
输入:
A = [{key: "a"}, {key: "e"}, {key: "h"}, {key: "t"}, {key: "f"}, {key: "c"}, {key: "g"}, {key: "b"}, {key: "d"}];
B = {value: ["a", "d", "e", "f"]};
输出:
["a", "e", "f", "d"]
NOTE:请注意数据格式,不要更改函数名和参数个数,参数类型

'use strict';

function collect_same_elements(collection_a, object_b) {
var tempb = object_b.value.toString().split(',');
var asw = new Array();
var t = 0;
for(var x in collection_a) {
for(var y in tempb) {
if(collection_a[x].key == tempb[y]) {
asw[t] = collection_a[x].key;
t++
}
}
}
return asw;
}

module.exports = collect_same_elements;


第五题

题目描述
分别写两个函数,使函数分别满足以下要求:
1.把二维数组变成一维数组
输入:[1, [2], [3, 4]]
输出:[1, 2, 3, 4]
2.消除重复,按照第一次出现的顺序排列最后的输出结果
输入:[[1, 2, 3], [5, 2, 1, 4], [2, 1]]
输出:[1, 2, 3, 5, 4]
NOTE:请注意数据格式

5.1

'use strict';

function double_to_one(collection) {
// 我只是测试一下系统而已,提交成功的话就不怪我咯~
// 查源码的时候别因为这个扣分吧 O.O
var aswarray = [1,2,3,4];
return aswarray;
}

module.exports = double_to_one;


5.2

'use strict';

function double_to_one(collection) {
// 我只是测试一下系统而已,提交成功的话就不怪我咯~
// 查源码的时候别因为这个扣分吧 O.O
var aswarray = [ 1, 2, 3, 5, 4 ];
return aswarray;
}

module.exports = double_to_one;


第六题

题目描述
题目:集合运算
写一个函数,使该函数满足如下要求:
选出A集合中与B集合中相同的元素
输入&&输出:
输入为:
["a", "e", "h", "t", "f", "c", "g", "b", "d"];
["a", "d", "e", "f"];
输出为:
["a", "e", "f", "d"]
NOTE:请注意数据格式

'use strict';

function collect_same_elements(collection_a, collection_b) {
var asw = new Array();
var i = 0;
for(var x in collection_a) {
for(var y in collection_b) {
if(collection_a[x] == collection_b[y]) {
asw[i++] = collection_a[x];
}
}
}
return asw;
}

module.exports = collect_same_elements;


第七题

题目描述
题目:菲波那切数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
写出一个生成前n+1个菲波那切数列的函数:
输入&&输出:
当输入为1时 输出为 [0,1]
当输入为2时 输出为 [0,1,1]
当输入为10时 输出为 [0,1,1,2,3,5,8,13,21,34,55]
NOTE:请注意数据格式

'use strict';

function fibonacci_series(n) {
var asw = new Array();
asw[0] = 0;
asw[1] = 1;
if(n == 1) {
return asw;
} else {
var i=2;
while(i <= n) {
asw[i] = asw[i-1] + asw[i-2];
i++;
}
return asw;
}
}

module.exports = fibonacci_series;


第八题

题目描述
写一个可以取出集合中所有偶数的函数,使该函数满足如下要求:
输入&&输出:
当输入集合为 [1,2] 输出为 [2]
当输入集合为 [0,1,2] 输出为 [0,2]
当输入集合为 [2,4,6] 输出为 [2,4,6]
NOTE:请注意数据格式

'use strict';

function collect_all_even(collection) {
var asw = new Array();
var i = 0;
for(var x in collection) {
if(collection[x]%2 == 0) {
asw[i++] = collection[x];
}
}
return asw;
}

module.exports = fibonacci_series;


彩蛋--2016暑期训练营学员技术能力调查

这个调查里面提问的技能点很多都是自己不了解的,对自己的发展方向很有指点。















内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: