Libraries solve the problems that we face on daily basis. Every problem has many different solutions. Python libraries are the hallmark of such varied solutions, that has been implemented by different programmers all around the world. The internet is filled with cookbooks, reciepes and code snippets.
Single Page to Learn and understand what a library is about and its basic syntax followed by the link that takes you to the libraries main page.
var decorData = data.map((frag) =>({ title:frag.topic_head.replace("_", " ").replace("/",""), desc: (frag) =>{ let temp = frag.data.replace('['," ").replace(']',""); return temp.split(',').join('\n') }, code: frag.code.replace('\n',"\r") }))
The above code using map function doesn't execute as intended. The aim is to clean the description by removing the square brackets, and add the space.
function cleanData(dataPoint){ dataPoint.code = dataPoint.code.replace(/(\r\n|\n|\r)/gm,"\r") dataPoint.topic_head = dataPoint.topic_head.replace("_", " ").replace("/",""); let t = dataPoint.data.replace('['," ").replace(']',""); dataPoint.data = t.split(',').join('\n') }
The above function works in cleaning the data on the fly. The replace function for removing the line breaks and carriage returns has to be regex
dataPoint.code .replace(/(\\n)/gm,"") .split(',') .join('\n')
Using the global and multiline modifier in the replace function helped to remove the \n characters. Even then there are still remaining characters that are unwanted.