目錄結構以下:javascript
這段時間陸陸續續的跑一些筆試,時間比較倉促,可貴有機會整理,下面跟你們分享一下23號去哪兒的筆試題。很少說,來正題。css
去哪兒一共有7道題,前三道是必答題,後面有兩道是前端必答題,還有最後兩道是測試必答題,其餘人選答,也就是說個人前端崗位,5道題必答,2道題選答。時間100分鐘。html
function padStart(string, minLength, padChar) { var strLen = string.length, result = ""; if (strLen <= 0 || strLen == minLength || strLen > minLength) { result = string; } else if (strLen < minLength) { var offset = minLength - strLen; for (var i = 0, len = offset; i < len; i++) { if (i == 0) { result = padChar + string; } else { result = padChar + result; } } } return result; } console.log(padStart("2010", 3, "0")); //2010 console.log(padStart("7", 4, "0")); //0007
function getParam(str){ var reg=/"[\w\s-]*"/g,result=[],m=0; var regResult=str.match(reg); //輸入字符串,返回按「-」分開後的數組 function toSplit(myStr){ var newStr = myStr.split("-"); newStr.shift(); for (var i = 0, len = newStr.length; i < len; i++) { newStr[i] = "-" + newStr[i]; } return newStr; } if(!regResult){ result=toSplit(str); }else{ var replaceStr=str.replace(/"[\w\s-]*"/g,"&");//將包含的「」部分用&代替 var tempArr=toSplit(replaceStr); for(var i=0,l=tempArr.length;i<l;i++){ if(tempArr[i].indexOf("&")!=-1){ tempArr[i]=tempArr[i].replace(/[&]/g,regResult[m++]);//將&用原字符串代替 } } result=tempArr; } return result; } var testStr='-name Lily -age 21 -school "Univrsity of -a Oxford" -address "-beijing -xichengqu 1-"'; console.log(getParam(testStr)); //["-name Lily ", "-age 21 ", "-school "Univrsity of -a Oxford" ", "-address "-beijing -xichengqu 1-""]
function diff(strA, strB) { var arrA = strA.split(""), arrB = strB.split(""), tempStr = "", strInA = "", strInB = "", result = ""; for (var i = 0, lenA = arrA.length; i < lenA; i++) { if (strB.indexOf(arrA[i]) == -1) { //A有B沒有 strInA = strInA + "-" + arrA[i] + ","; } else { tempStr = tempStr + arrA[i]; } } for (var j = 0, lenB = arrB.length; j < lenB; j++) { if (tempStr.indexOf(arrB[j]) == -1) { strInB = strInB + "+" + arrB[j] + ","; } } result = strInA + strInB; result = result.slice(0, -1); return result; } console.log(diff("abce", "abcd")); //-e,+d
a) .div1{position:absolute;float:left} .div2{position:absolute;float:right}
b) .div1{postition:relative;float:left} .div2{position:relative;float:right}
c) .div1{position:absolute;float:right} .div2{position:relative;float:left}
function indexOf(strA, strB) { var lenA = strA.length, lenB = strB.length; if (lenA < lenB) { return -1; } else if (strA === strB) { return 0; } else { for (var j = 0; j < lenA; j++) { if (strA.charAt(j) == strB[0] && strA.substr(j, lenB) == strB) { return j; } } return -1; } } console.log(indexOf("hello", "el")); //1
本人前端菜鳥,能力有限。其實去哪兒的筆試題仍是蠻基礎的,可是本身有些題目作的有瑕疵。把題目列出來,主要是給你們一個參考。另外,題目答案本身作的不必定正確,歡迎留言拍磚。代碼確定有大量須要優化的地方,但願各位提出意見,你們共同進步,祝各位基友軟妹子找到理想工做。前端