码迷,mamicode.com
首页 > 编程语言 > 详细

每天一个JavaScript实例-递归实现反转数组字符串

时间:2014-10-14 13:08:58      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   java   div   2014   on   cti   

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-递归实现反转数组字符串</title>
<script>
var func = function(x,indx,str){
	return indx == 0 ? str : func(x,--indx,(str +=" " + x[indx]));;
	}
var arr = new Array("apple","banna","orange","apple2","apple3");
var arr1 = arr.slice(0)
var arr3 = func(arr1,arr1.length,"");
var arr2 = arr.slice(0).reverse();
console.log(arr2);
console.log(arr);
console.log(arr3);

</script>
</head>

<body>

<div id = "date">
</div>

</body>
</html>

每天一个JavaScript实例-递归实现反转数组字符串

标签:blog   http   io   ar   java   div   2014   on   cti   

原文地址:http://blog.csdn.net/waiting7436/article/details/40073649

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!