Discuss / JavaScript / 最后面两题怎么做啊

### 最后面两题怎么做啊

Topic source

#### 一十四蓝

#1 Created at ... [Delete] [Delete and Lock User]

#### 乖乖静陌儿

#2 Created at ... [Delete] [Delete and Lock User]

var arr = s.split(""); var a = arr.map(Number); var n; if(a.length === 1){ n = a[0]; }else{ n = a.reduce(function (x, y) { return x * 10 + y; }); } return n;

return arr.map(pow);

#### 乖乖静陌儿

#3 Created at ... [Delete] [Delete and Lock User]
``````function pow(x) {
return x * 1;
}

var arr = s.split("");
var a = arr.map(pow);
var n;
if(a.length  === 1){
n = a[0];
}else{
n = a.reduce(function (x, y) {
return x * 10 + y;
});
}
return n;
``````

#### 廖雪峰

#4 Created at ... [Delete] [Delete and Lock User]

#### MinamiyaNatsuki

#5 Created at ... [Delete] [Delete and Lock User]
``````在此插入代码
``````

<script> function string2int(s) { var arr = []; for (var i = 0; i < s.length; i++) { arr.push(s[i]); alert(typeof arr[i]); }

``````alert(arr);
return arr.reduce(function(x, y) {
return (+x) * 10 + (+y)
});
``````

}

function pow(x) { var first = x.substring(0,1); var el = x.substring(1); var result = first.toUpperCase() + el.toLowerCase();

``````return result;
``````

}

function normalize(arr) { return arr.map(pow); }

// 测试: // var result = string2int("12345"); // alert(result);

var result = normalize(['adam', 'LISA', 'barT']); alert(result); </script> 在atom上写的代码 廖大大 为啥 我第一个在你的网页上 通过不了

#### g100526T_T

#6 Created at ... [Delete] [Delete and Lock User]
``````var num = [];
for(var i = 0; i < s.length; i++){
num.push(s[i]);
}
function s2n(string){
switch(string)
{
case "1":
return 1;
break;
case "2":
return 2;
break;
case "3":
return 3;
break;
case "4":
return 4;
break;
case "5":
return 5;
break;
case "6":
return 6;
break;
case "7":
return 7;
break;
case "8":
return 8;
break;
case "9":
return 9;
break;
case "0":
return 0;
break;
}
}
var num = num.map(s2n);
var rs = 0;
num.reduce(function(x,y){
rs = 10*x + y;
return rs;
})
return rs;
``````

• 1