Search notes:

Javascript: create all element pairs of an array

The following example demonstrates a method to produce an array that contains all combinations of pairs of an array.
function createAllPairs(list) {

   return list.reduce( (accu, item, i, arr) =>
   //
   // Iterattion over each element in list
   //
      accu.concat(
         arr.slice(i + 1).           // Create an array of the elements beyond the current element …
         map(_item => [item, _item]) // … and create a «pair» for each element.
      )
      ,
   // The following empty array will be passed as
   // initial value for accue to reduce() and
   // populated with pari-combinations in each
   // iteration:
      []
   );

}

let result = createAllPairs(['one', 'two', 'three', 'four', 'five']);

result.forEach(pair => print(`${pair[0]} - ${pair[1]}`));

Links

This Stackoverlow answer was quite helpful to me

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759414054, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/JavaScript/objects/Array/pairwise-combination(61): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78