Google Sheets – Permutation of Characters Horizontally

formulasgoogle sheetsgoogle-apps-scriptgoogle-sheets-arrayformulagoogle-sheets-custom-function

I am stuck here in printing permutation of two or more characters horizontally along that row in which the characters are.
Is it possible? Because I searched it all over and only found vertical output along the column.

I have to make permutations of different people from different community and create their user names. The below is what I get after entering my formula

enter image description here

Here is the code:

function permuteEmails(a,b,c) {
  var ssheet = SpreadsheetApp.getActive();
  var sheet = ssheet.getSheetByName('Person Details');
  var array = [];

  var aVal = sheet.getRange(a).getDisplayValue();
  var bVal = sheet.getRange(b).getDisplayValue();
  var cVal = sheet.getRange(c).getDisplayValue();

  var aVal_first = aVal.slice(0,1);
  var bVal_first = bVal.slice(0,1);

  array.push(aVal + "." + bVal + "@" + cVal);
  array.push(bVal + "." + aVal + "@" + cVal);
  array.push(aVal + "@" + cVal);
  array.push(aVal + "." + bVal_first + "@" + cVal);
  array.push(aVal + bVal_first + "@" + cVal);
  array.push(aVal_first + bVal + "@" + cVal);

  return array;
}

But I want it to look like, that after entering the details and applying the formula, all the combinations should print along the same row in which we entered the details.

Best Answer

  • try: =TRANSPOSE(PERMUTEEMAILS("A2", "B2", "C2"))

    0

  • or use this:

    =ARRAYFORMULA(IF(LEN(C2:C), LOWER({
     A2:A&"."&B2:B&"@"&C2:C, 
     B2:B&"."&A2:A&"@"&C2:C,
     B2:B&"@"&C2:C,
     B2:B&"."&LEFT(A2:A, 1)&"@"&C2:C,
     B2:B&LEFT(A2:A, 1)&"@"&C2:C,
     LEFT(B2:B, 1)&A2:A&"@"&C2:C}), ))

    0