Seems simple enough:
const variableNameify = (words) => words.map((word, index) => index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
If you want to measure the time:
const measureTime = (fn, args) => {
const startTime = performance.now();
try {
return fn.call(this, args);
} finally {
const endTime = performance.now();
console.log("Call to", fn, args, "took", (endTime - startTime), "ms");
}
};
console.log(measureTime(variableNameify, ['is', 'prime']));
console.log(measureTime(variableNameify, ['remove', 'last', 'vowel']));
console.log(measureTime(variableNameify, ['MaX', 'VALUE']));
On my machine, the execution time is too small to measure; all three calls show it taking 0ms.