I have a long function, which takes a long string (an example is in the end) without any dots or comas, makes a 1D array and then 2D array. Then from 2D array, I create an array of objects and then return it as the components in React application.
However I’m facing the following issues, and currently do not know how to overcome them:
- when I filter with countries regex, I replace them, how to avoid it and have the endless line split
- If you see on the example - in the lists, there are Team rows. I didn’t figure out how to exclude them when I’m mapping and pushing into the array.
arr:[...e]
I was trying to do the for loop to exclude specifically, but it didn’t work as I cannot assign a function to a key.
I sincerely ask for help, as I stuck.
const TeamList =(props)=>{
let regex = /Team/gi
let newExample = props.argument.replace(regex, '\enterTeam').split('\enter')
let regx = /Ukraine|Grenada|Denmark|Switzerland|Pakistan|USA|India|Canada|Colombia|Venezuela|Brazil|United States/g
let array2 = newExample.map(element => {
return element.toString().replace(regx,'asd').split('asd')});
let array3=[];
array2.map((e,i)=>{ array3.push({title: e[0], arr:[...e]}) })
return (
<div>
{array3.map((e,i)=>{return <div style={{width: '50vw', margin:'3vw auto 1vw auto'}} ><h3>{e.title}</h3> <ul>{e.arr.map((el,ind)=>{return <li>{el}</li>})}</ul></div>})}
</div>
)
}
Had an idea to
-
split the string on 2nd occurrence of coma, so I will have this as array1 = [‘team 20, company x’ , ‘Ukraine team members’]
-
Split the value at the second index of array1 based on the first occurrence of space which will end up as array2 = [‘Ukraine’, ‘team members’];
-
In my component then I will have: title: First index of array 1 + 1st index of array 2 description: 2nd index of array 2
But the question here is that I cannot split on the index of the second coma. A Separator can be regex or a word. If we slice - then I have to make the whole new function inside the function, which is not good I guess?
So can anyone help me with that, please?
let example =‘Team 51, Client Company: Calgary International Airport, Canada Heather Glenn, Florida Atlantic University, Instructor: Daniel Rottig, USA Karen Cerquera Molina, Universidad EAN, Instructor: Juan Manuel Gil, Colombia Maeva Magmui, Massey University, Instructor: Dirk Boehe, Venezuela Marcos Soares, Federal University of Parana, Instructor: Germano Glufke Reis, Brazil Maxwell Darko Addo, Kwame Nkrumah University of Science and Technology, Instructor: Samuel Yaw Akomea, Ghana Team 57, Client Company: OGG, Brazil Alexa Ralston, Nazareth College, Instructor: Jennifer SA Leigh, USA Joao Victor Poffo Oliveira, Universidade Regional de Blumenau, Instructor: Germano Adolfo Gehrke, Brazil Juan Felipe Acosta Munoz, EAFIT, Instructor: Daniel Gomez, Colombia Tyler Broughton-Ambrose, Johnson & Wales University, Instructor: Leilani Baumanis United States Team 112, Client Company: Lady Bay, Australia Ashleigh John, St. George’s University, Instructor: Reccia Charles, Grenada Cynthia Rivas, Georgia Gwinnett College, Instructor: Luis Torres, USA Morena T. Matshego, University of Botswana, Instructor: Tendy Matenge, Botswana Sara Maria Chinchilla Echeverri, EAFIT, Instructor: Daniela Acosta, Colombia Sara Yusty Salazar, EAFIT, Instructor: Carolina Garcia, Colombia’