Last active
November 9, 2018 08:28
-
-
Save dexteryy/91432c7a26557c8ddf66b122ee7f3146 to your computer and use it in GitHub Desktop.
js question for tudou (2009)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ================================================================== | |
* 要求: | |
* 1, 只能在指定的位置填写自己的代码,本文件里的其他代码不能修改 | |
* 2, 所有题目都不允许添加全局变量名 | |
* 3, 本文件应该能在console里正常执行,并输出结果 | |
* 4, 共4题,至少做2题 | |
* ================================================================== | |
*/ | |
/** | |
* ================================================================== | |
* 题1: 实现一个遍历数组或对象里所有成员的迭代器 | |
* ================================================================== | |
*/ | |
var each = function(obj, fn){ | |
//+++++++++++答题区域+++++++++++ | |
//+++++++++++答题结束+++++++++++ | |
}; | |
try{ | |
var data1 = [4,5,6,7,8,9]; | |
var data2 = { | |
"a": 4, | |
"b": 5, | |
"c": 6 | |
}; | |
console.group(data1); | |
each(data1, function(o){ | |
if( 6 == this ) | |
return true; | |
else if( 8 == this ) | |
return false; | |
console.log(o + ": \"" + this + "\""); | |
}); | |
console.groupEnd(); | |
/*------[执行结果]------ | |
1: "4" | |
2: "5" | |
4: "7" | |
------------------*/ | |
console.group(data2); | |
each(data2, function(v, n){ | |
if( 5 == this ) | |
return true; | |
console.log(n + ": \"" + v + "\""); | |
}); | |
console.groupEnd(); | |
/*------[执行结果]------ | |
a: "4" | |
c: "6" | |
------------------*/ | |
}catch(e){ | |
console.error("第1题执行出错,错误信息: " + e); | |
} | |
/** | |
* ================================================================== | |
* 题2: 实现一个叫Man的类,包含attr, words, say三个方法 | |
* ================================================================== | |
*/ | |
var Man; | |
//+++++++++++答题区域+++++++++++ | |
//+++++++++++答题结束+++++++++++ | |
try{ | |
var me = Man({ fullname: "小红" }); | |
var she = new Man({ fullname: "小红" }); | |
console.group(); | |
console.info("我的名字是:" + me.attr("fullname") + "\n我的性别是:" + me.attr("gender")); | |
console.groupEnd(); | |
/*------[执行结果]------ | |
我的名字是:小红 | |
我的性别是:<用户未输入> | |
------------------*/ | |
me.attr("fullname", "小明"); | |
me.attr("gender", "男"); | |
me.fullname = "废柴"; | |
me.gender = "人妖"; | |
she.attr("gender", "女"); | |
console.group(); | |
console.info("我的名字是:" + me.attr("fullname") + "\n我的性别是:" + me.attr("gender")); | |
console.groupEnd(); | |
/*------[执行结果]------ | |
我的名字是:小明 | |
我的性别是:男 | |
------------------*/ | |
console.group(); | |
console.info("我的名字是:" + she.attr("fullname") + "\n我的性别是:" + she.attr("gender")); | |
console.groupEnd(); | |
/*------[执行结果]------ | |
我的名字是:小红 | |
我的性别是:女 | |
------------------*/ | |
me.attr({ | |
"words-limit": 3, | |
"words-emote": "微笑" | |
}); | |
me.words("你好,我喜欢土豆。"); | |
me.words("土豆的办公室太漂亮了。"); | |
me.words("土豆的美女真多!"); | |
me.words("但是土豆视频的速度太慢了,我平时都看优酷!"); | |
console.group(); | |
console.log(me.say()); | |
/*------[执行结果]------ | |
小明微笑:“我喜欢土豆。土豆的办公室太漂亮了。土豆的美女真多!” | |
------------------*/ | |
me.attr({ | |
"words-limit": 2, | |
"words-emote": "喊" | |
}); | |
console.log(me.say()); | |
console.groupEnd(); | |
/*------[执行结果]------ | |
小明喊:“我喜欢土豆。土豆的办公室太漂亮了。” | |
------------------*/ | |
}catch(e){ | |
console.error("第2题执行出错,错误信息: " + e); | |
} | |
/** | |
* ================================================================== | |
* 题3: 实现一个URI解析方法,把url里#之后的参数解析成指定的数据结构 | |
* ================================================================== | |
*/ | |
function urlParser(s){ | |
//+++++++++++答题区域+++++++++++ | |
//+++++++++++答题结束+++++++++++ | |
} | |
try{ | |
var url1 = "http://www.tudou.com/my/sub/#page/2/?type=latest_videos&page_size=20"; | |
var url2 = "http://www.tudou.com/my/sub/#type=latest_videos&page_size=20"; | |
var url3 = "http://www.tudou.com/my/sub/#page?type=latest_videos&page_size=20"; | |
console.group(); | |
console.info( urlParser(url1) ); | |
console.info( urlParser(url2) ); | |
console.info( urlParser(url3) ); | |
console.groupEnd(); | |
/*------[执行结果]------ | |
["page", "2", { "type": "latest_videos", "page_size": 20 }] | |
[{ "type": "latest_videos", "page_size": 20 }] | |
["page", { "type": "latest_videos", "page_size": 20 }] | |
------------------*/ | |
}catch(e){ | |
console.error("第3题执行出错,错误信息: " + e); | |
} | |
/** | |
* ================================================================== | |
* 题4: 把文本流改成指定行数的从右到左从上到下的方块,假设所有字符都是全角中文 | |
* ================================================================== | |
*/ | |
function changeFlow(){ | |
//+++++++++++答题区域+++++++++++ | |
//+++++++++++答题结束+++++++++++ | |
} | |
try{ | |
console.log( changeFlow("我喜欢土豆。土豆的办公室太漂亮了。", 4) ); | |
/*------[执行结果]------ | |
太的豆我 | |
漂办,喜 | |
亮公土欢 | |
了室豆土 | |
------------------*/ | |
}catch(e){ | |
console.error("第4题执行出错,错误信息: " + e); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment