Adding periods between letters of words across a number of columns

Hi there

I have some code running in the backend which adds periods/dots between each letter of a word at a time when it’s submitted by the user (ie as a beforeInsert hook)

I would like to repeat this across 30 columns, but I’m struggling to get my addPeriods function (below) to work, so I’ve currently got it as part of the body of the code, which works fine to operate once, but not to repeat across 30 columns.

Can you help me
a) fix the function below, so I can write item.word_spelled1 = addPeriods(item.word1)
b) and/or suggest a better way than repeating this line 30 times for item.word_spelled2, item.word_spelled3 etc etc to iterate the calculation 30 times?

NB there is some other code (incrementString function) I’m using to apply an incrementing alpha identifier which is working fine.

Many thanks!

import wixData from ‘wix-data’;

//this bit’s working OK
function incrementString(value) {
let carry = 1;
let res = ‘’;

for ( let i = value.length - 1; i >= 0; i–) {
let char = value.toUpperCase().charCodeAt(i);

char += carry;

if ( char > 90) {
char = 65;
carry = 1;
} else {
carry = 0;
}

    res = String.fromCharCode( **char** ) + res; 

if (!carry) {
res = value.substring(0, i) + res;
break ;
}
}

if (carry) {
res = ‘A’ + res;
}

return res;
}

//this is the function I can’t get to work
function addPeriods(word) {
word.split(‘’).map( function (v) { // split the string into individual char array
return v + ‘.’; // iterate and update
}).join(‘’) // join the updated array

}

export function SpellingTestsNew_beforeInsert(item, context) {

let numberOfItems;
wixData.query(“SpellingTestsNew”)
.find()
.then((results) => {
numberOfItems = results.items.length // this represents the number of items in the database collection.
});

return wixData.query(“SpellingTestsNew”)
.limit(1)
.descending(‘_createdDate’) // descending() sorts the results in descending order by property, i choose “_createdDate”
.find()
.then((results) => {
const lastItemInCollection = results.items[0];
item.id2 = incrementString(lastItemInCollection.id2); // “id2” is a unique incrementing alpha identifier eg ASA
item.word_spelled1 = item.word1.split(‘’).map( function (v) {// adds a version of the word with periods between each letter to a different column
return v + ‘.’; // iterate and update
}).join(‘’)// join the updated array
return item; // beforeInsert function returns the item
});

}