From 942a302ae181df8cef5f6241d45999075919c358 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 24 Mar 2024 21:11:37 -0400 Subject: [PATCH] Fix --- commands/edit-text/yoda.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/commands/edit-text/yoda.js b/commands/edit-text/yoda.js index faaa0501..707399ff 100644 --- a/commands/edit-text/yoda.js +++ b/commands/edit-text/yoda.js @@ -26,13 +26,13 @@ module.exports = class YodaCommand extends Command { yodaSpeak(text) { const sentences = text.split(/\?|!|\./); - const newSentences = []; + let newSentences = []; for (const sentence of sentences) { const trimmed = sentence.trim(); const breaks = trimmed.split(','); const newBreaks = []; for (const broke of breaks) { - let newText = []; + const newText = []; const pivoted = []; const words = broke.split(' '); for (let i = 0; i < words.length; i++) { @@ -45,11 +45,14 @@ module.exports = class YodaCommand extends Command { newText.push(clean); } } - newText = newText.map((word, i) => i === 0 ? firstUpperCase(word) : word); newBreaks.push(`${newText.join(' ').trim()} ${pivoted.join(' ').trim()}`); } newSentences.push(newBreaks.join(', ').trim()); } + newSentences = newSentences.map(sentence => { + const split = sentence.split(' '); + return split.map((word, i) => i === 0 || word === 'i' ? firstUpperCase(word) : word); + }); return `${newSentences.join('. ').trim()} ${ends[Math.floor(Math.random() * ends.length)]}`; } };