Question

Write a function named "csv_to_list" that takes a string as a parameter representing the name of...

Write a function named "csv_to_list" that takes a string as a parameter representing the name of a CSV file with 5 columns in the format "<int>,<int>,<int>,<int>,<int>" and returns a new list containing all the values in the third column as integers in the same order they appear in the input file
//JAVASCRIPT //
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8/> </head> <body> <script> function func(file) { //create a raw

alert(li); return li; rawFile.send(null) </script> <input type=file id=file> <input type=submit onclick=func(women_to

OUTPUT:

used alert to show the output

the file used in this program

1,2,3,4,5 2,3,4,5,6 3,4,5,6,0.1

actual output in browser

This site says... 3,4,5,6,0 ок

CODE TO COPY:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8"/>
    </head>
    <body>
        <script>
            function func(file){
                //create a raw file
                var rawFile = new XMLHttpRequest();
                //use that file to open local file
                rawFile.open("GET", file, false);
                rawFile.onreadystatechange = function ()
                {
                    if(rawFile.readyState === 4)
                    {
                        if(rawFile.status === 200 || rawFile.status == 0)
                        {
                            //getting all content from the file
                            var allText = rawFile.responseText;
                            //split the content on newline
                            var some=allText.split("\n");
                            //selecting 3rd line
                            var some1=some[2];
                            //split the 3rd line on comma
                            var some2=some1.split(",");
                            //creating list of 5 elements by parseint
                            var li=[parseInt(some2[0]),parseInt(some2[1]),parseInt(some2[2]),parseInt(some2[3]),parseInt(some2[4])]
                            //returning that list
                            alert(li);
                            return li;
                        }
                    }
            }
            rawFile.send(null)
        }
        </script>
        <input type="file" id="file">
        <input type="submit" onclick="func('women_top.csv')">
        <div id="fileContents"></div>
    </body>
</html>

Add a comment
Know the answer?
Add Answer to:
Write a function named "csv_to_list" that takes a string as a parameter representing the name of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT