, ,

[SOLVED] Cosc484 assignment 4

$25

File Name: Cosc484_assignment_4.zip
File Size: 188.4 KB

5/5 - (1 vote)

The goal is to demonstrate you knowledge of File I/O and JSON to parse text files as well as utilize
the asynchronous properties of JavaScript. Look at readFile and readdir functions for parts 3 & 4.
Important: If you are on a Windows machine, do not take into account /r
for anything, you will lose points if you do. Also, if you use the ES6 import
statement instead of the CommonJS require for node modules taught during
lecture, you will lose 10%.
Specifications
For this assignment, you will need to understand File I/O and how to use an
asynchronous function in JavaScript.
Part 1: File I/O & JSON
Create a file called toJSON that reads a .txt file from the command line. This
file should always contain at least three lines:
• line 1: is a first name (1 word)
• line 2: is a last name (1 word)
• line 3: is a location (1 word)
• lines 4-n: can be string(s) (n # of word(s))
Your job is to take this data and out a clean JSON object in the following format:
fname: line1 fname, lname: line2 lname, location: line 3, other: lines 4-lines n
The only edge cases that need to be considered are:
• If there are not at least three lines in the file, print an error message and
do no further processing on the file
• Only one arg is read in through the command line which is the filename.
If more than one arg is provided, print an error message and do no further
processing on the file
• If there are only three lines, other will contain “N/A”
1
Part 2: to Array
Create a file called toArray.js that reads n numbers from the command line,
adds only the even numbers to an array, and returns the array in the order that
they were entered. You must use a forEach loop for this file. The output will
contain the size of the array and the array itself.
Part 3: String Count
Create a file called stringCount.js that reads a textfile from the command line.
You must return the total number of occurrences that the following words in
the textfile (case should be ignored):
• towson
• cis
• web
• development
Please note: this should only count if one of the four words is a stand-alone
word, not if it is contained within another word. For example, if a textfile contained the string “Welcome to TowsonCIS”, the value returned would be 0. But
if the textfile contained the string “Welcome to Towson CIS” the value returned
would be 2.
Part 4: File Count
Write a program called asyncFileCount.js that prints the number of files with
a given extension in a given directory. The first argument will be the path to
the directory we want to filter on (e.g. ‘/path/to/dir/’) and a file extension to
filter by as the second argument.
For example, if you get ‘.txt’ as the second argument then you will need to filter
the list to only files that end with .txt
2
Below are some example runs:
An example run would be: node asyncFileCount.js . .js
Another example run would be: node asyncFileCount.js /Users/jalirani/Desktop
.docx
Submission
Please submit the following on Blackboard:
• toJSON.js
• toArray.js
• stringCount.js
• asyncFileCount.js

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Cosc484 assignment 4[SOLVED] Cosc484 assignment 4
$25