I have a text file with two sentences, one on line 1 and the other sentence on line 2
Example:
line 1: The foo is black
line 2: The bar barks
The contents of line 1 and line 2 would be put inside of an array
example: ['The foo is black', 'The bar barks']
Now that I have these two inside an array I want to loop through the array and put each word in the sentence inside of an object along with the line number it is on. Example:
{
barks : 2 //line 2
black : 1 //line 1
foo: 1
bar: 2
is : 1
the : 1, 2
}
how can I approach this? I thought that I could loop through the array and then add each word to an object but the output does not necessarily have to be in an object, that was just my thinking. It's important to note that the output must be sorted in alphabetical order as well.