Last active
August 29, 2015 14:01
-
-
Save jikeytang/7f8667dafbd92cc35ff7 to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140521-题目2
This file contains hidden or 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
输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,其它位置的保持不变,最后输出数组。 | |
回复时注意加上下面这句话,才会有语法高亮或格式缩进。 | |
```javascript |
wsgouwan
commented
Nov 28, 2014
var get_arr_size = function(_arr){
var arr = _arr || [1, 4, 3, 5, 7, 5, 2, 3, 4, 7],
arr_str = arr.join(''),
max = Math.max.apply(null, arr),
min = Math.min.apply(null, arr),
arr_str_clear = arr_str.replace(/,/g, ''),
max_index = arr_str_clear.indexOf(max),
min_index = arr_str_clear.indexOf(min);
return {
max : {
index : max_index,
value : max
},
min : {
index : min_index,
value : min
}
};
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment