js 取不同数组的相同元素 函数 fGetTheSame

类别: Javascript, function
标签: js, array, func, fGetTheSame, same
摘要: ..
正文:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
 var Ar = [01234];
 var Ar1 = [23456];
 var Ar2 = [45678];
 var Ar3 = [45678910];
 
 document.write("Ar: ", Ar, "<br/>");
 document.write("Ar1: ", Ar1, "<br/>");
 document.write("Ar2: ", Ar2, "<br/>");
 document.write("Ar3: ", Ar3, "<br/>");
 document.write("<hr/>");
 
 document.write("fGetTheSame(Ar):", fGetTheSame(Ar)"<hr/>");
 document.write("fGetTheSame(Ar, Ar1):", fGetTheSame(Ar, Ar1)"<hr/>");
 document.write("fGetTheSame(Ar1, Ar2, Ar3):", fGetTheSame(Ar1, Ar2, Ar3)"<hr/>");
 document.write("fGetTheSame(Ar, Ar1, Ar2, Ar3):", fGetTheSame(Ar, Ar1, Ar2, Ar3)"<hr/>");
 
 function fGetTheSame()
 {// shawl.qiu code : return Array
  var Arg = arguments;
  var Len = Arg.length;
  if(Len<1) throw new Error("参数错误, 必须最少为一个数组!");
  var TempLen = Len;
  while(--TempLen>-1) if(Arg[TempLen].constructor!=Array) throw new Error("参数必须为数组!");
  if(Len===1) return Arg[0];
  var Ar = Arg[0].slice();
  var ResultAr = [];
  for(var i=0, j=Ar.length; i<j; i++)
  {
   var HasAr = [];
   for(var I=1; I<Len; I++)
   {
    for(var J=0, K=Arg[I].length; J<K; J++)
    {
     if(Ar[i]===Arg[I][J])
     {
      HasAr.push(true);
      break;
     }
    } // end for 2
   } // end for 1
   if(HasAr.length===Len-1) ResultAr.push(Ar[i]);
  } // end for
  return ResultAr;
 } // end function fGetTheSame()
/*]]*/
</script>
</body>
</html>

 
文章相关信息:
主题: js 取不同数组的相同元素 函数 fGetTheSame
发表者: shawl.qiu
电子邮件: shawl.qiu@gmail.com
QQ: 908202921
MSN: btbtd@msn.com
Homepage: http://www.btbtd.org/
Blog: http://blog.csdn.net/btbtd/
发表日期: 2007-8-29 12:23:53
更新日期: 2007-8-29 12:23:53
来源引用: shawl.qiu CSharp DotNet 个人资料管理系统
引用本页: http://gi.2288.org/mod/code/display/Default.aspx?aid=543
关闭
Google
搜索WWW
搜索www.btbtd.org
搜索blog.csdn.net
Powered by shawl.qiu © 2008-2010 the shawl.qiu Javascript Kits
Copyright © 2008-2010 by shawl.qiu