In: Computer Science
Hello, I have a problem with understanding this line.
forEach(value.split("<br>"), line, line.trim()).slice(-3).join("\n")
This line is for the open refine program. Could you tell me what this line is trying to do? I have no idea what this is for...
For your information, this line appeared when professor was talking about 'Fetching and Parsing HTML'..
Thank you for answering my question and have a good day!
p.s. My professor told us to insert that line in the expression box and try to figure out what this expression means... As I'm not majoring in CS, it's too difficult for me to understand..;(
. A forEach() statement asks for an array, a variable name, and an expression applied to the variable. Following the form forEach(array, variable, expression), construct the loop using these parameters:
ARRAY----its value.split("<br />"),(not "<br>which you ask in question ) creates an array from the lines of the sonnet in each cell
VARIABLE-----line, each item in the array is then represented as the variable (it could be anything, v is often used)
AN EXPRESSION TO BE APPLIED ON VARIABLE--
line.trim(), each item is then evaluated separately with the specified expression. In this case, trim() removes the white space from each sonnet line in the array.
As, the results of the forEach() are returned as a new array, additional array functions can be applied, which are slice and join. Add slice(1) to remove the sonnet number, and join("\n") to concatenate the lines in to a string value .
forEach(value.split("<br/>"), line, line.trim()).slice(-3).join("\n")