Is there a way to match multiple words from a paragraph while omitting commas, full stops, spaces and case sensitivity? Better yet, return the answer with a list of ascending number in front.
I received this forwarded message during Christmas and thought I'd have some fun using code to solve it.
const paragraph = "I once made a remark about the hidden books of the Bible. A certain luke, kept people looking so hard for facts, and for others, it was a revelation. Some were in a jam, especially since the names of the books were not capitalized. But the truth finally struck home to numbers of our readers. To others it was a job. We want it to be a most fascinating little moment for you. Yes, there will be some really easy ones to spot. Others may require judges to help find them. I will be quickly admit it usually takes a minister to find one of them, and there will be loud lamentations when it is found. A little lady says she brews a cup of tea so she can concentrate better. See how well compete. Relax now, for there really are sixteen books of the Bible in this paragraph."
function findBooks() {
let newParagraph = paragraph.toLowerCase();
let regEx = /[.,\s]/g;
let workingPara = newParagraph.replace(regEx, '');
let matches = workingPara.match(/(genesis|exodus|leviticus|numbers|deuteronomy|joshua|judges|ruth|samuel|kings|chronicles|ezra|nehemiah|esther|job|psalms|proverbs|ecclesiastes|songofsolomon|isaiah|jeremiah|lamentations|ezekiel|daniel|hosea|joel|amos|obadiah|jonah|micah|nahum|habakkuk|zephaniah|haggai|zechariah|malachi|matthew|mark|luke|john|acts|romans|corinthians|galatians|ephesians|philippians|colossians|thessalonians|timothy|titus|philemon|hebrews|james|peter|john|jude|revelation)/g).join(', ');
return matches;
}
findBooks();
I was thinking of listing the Bible books as an array and match them to the message but found I could only do one book at a time, and i didn't want to manually check it one by one. I thought of looping through the array but it didn't work. I know the final answer to be 16 and wanted to added a number list infront of the answer but again, it didn't work. Also wanted to capitalize the first letter of the book but realise that the whole answer is an entire string, so couldn't use the charAt[0].toUpperCase() method.
Happy enough with the answer generated from my code but an enhancement would be better. (eg 1 Mark, 2 John, etc)