D3.js中的d3.cross()函數用於返回給定兩個數組A和B的笛卡爾積。
用法:
d3.cross(Array1, Array2)
參數:此函數接受上麵提到並在下麵描述的兩個參數:
- Array1:這是第一個將與array2進行笛卡爾乘積運算的數組。
- Array2:這是第二個數組,其元素將與array1進行笛卡爾積。
返回值:它返回兩個給定數組的two-element的笛卡爾乘積數組。
以下程序說明了D3.js中的d3.cross()函數。
示例1: 
<html> 
  
<head> 
    <title> 
      Getting cartesian product 
      of the two given array 
  </title> 
</head> 
  
<body> 
    <script src='https://d3js.org/d3.v4.min.js'> 
  </script> 
  
    <script> 
        // initialising the array of elements 
        var Array1 = [10, 20, 30]; 
        var Array2 = [1, 2, 3]; 
  
        // Calling to d3.cross() function 
        A = d3.cross(Array1, Array2); 
  
        // Getting cartesian product of the two given array 
        document.write(A + "<br>"); 
    </script> 
</body> 
  
</html>輸出:
[[10, 1], [10, 2], [10, 3], [20, 1], [20, 2], [20, 3], [30, 1], [30, 2], [30, 3]]
示例2:
<html> 
  
<head> 
    <title> 
      Getting cartesian product  
      of the two given array 
  </title> 
</head> 
  
<body> 
    <script src='https://d3js.org/d3.v4.min.js'> 
  </script> 
  
    <script> 
        // initialising the array of elements 
        var Array1 = ["A", "B", "C"]; 
        var Array2 = ["a", "b", "c"]; 
  
        // Calling to d3.cross() function 
        A = d3.cross(Array1, Array2); 
  
        // Getting cartesian product of the two given array 
        document.write(A + "<br>"); 
    </script> 
</body> 
  
</html>輸出:
[[A, a], [A, b], [A, c], [B, a], [B, b], [B, c], [C, a], [C, b], [C, c]]
參考: https://devdocs.io/d3~4/d3-array#cross
相關用法
- PHP each()用法及代碼示例
- p5.js day()用法及代碼示例
- p5.js int()用法及代碼示例
- p5.js second()用法及代碼示例
- PHP dir()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js arc()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- p5.js str()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 D3.js | d3.cross() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
