Maybe you guys have an idea, thanks in advance community!
I'm current getting the Error:
Text result of JOIN is longer than the limit of 50000 characters
within Google Sheets when using this formula
=TRANSPOSE(SPLIT(JOIN(",";B1:B7);","))
I thought I could create a workaround in Google AppScript but my code is not working properly on the front end.
Current code:
function masterJoin(value) {
//var delim = ","
//var value = [["employee1","employee2"],["employee3"]]
//delim = delim || '';
var result = [];
for (var i = 0; i < value.length; i++){
//result.push(value[i]);
//Logger.log(result);
var temp = value[i]
for (var t = 0; t < temp.length; t++){
//Logger.log(temp[t])
result.push(temp[t])
}
}
return result
}
[["employee1,employee2"],["employee3"]]
and not like [["employee1","employee2"],["employee3"]]
. In the former case, they're strings. In the latter case, they're arrays.(They're not!)Use recursion to recurse over all elements
Split the string elements and
Flatten the resulting array
/**
* Simulates TRANSPOSE(SPLIT(JOIN(",",array),","))
* @param {Object[][]} array2d The two dimensional array passsed from Google sheet
* @returns {String[]} 1D array - 1D is enough for custom function
* @customfunction
*/
const masterJoinFixed = array2d => recursiveFunc_(array2d).flat(3);
/**
* Recursive helper function to split all elements
* of a multi dimensional array by comma `,`
* @param {Object[]|String} arrOrString
* @returns {Object[]}
* @private
*/
const recursiveFunc_ = arrOrString =>
Array.isArray(arrOrString)
? arrOrString.map(recursiveFunc_)
: String(arrOrString).split(',');
/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/ const masterJoinFixed = array2d => recursiveFunc_(array2d).flat(3); const recursiveFunc_ = arrOrString => Array.isArray(arrOrString)? arrOrString.map(recursiveFunc_): String(arrOrString).split(','); console.info(masterJoinFixed([['1,2,3'],[4],[5]]))
<:-- https.//meta.stackoverflow:com/a/375985/ --> <script src="https.//gh-canon.github.io/stack-snippet-console/console.min.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.