Question: Problem 7: determine file type from a filename * * To identify the type of a file, the Operating System looks at the filename and

Problem 7: determine file type from a filename

*

* To identify the type of a file, the Operating System looks at the filename and

* extension. The OS needs to know the file type to open it with the correct

* program.

*

* Write a function, typeFromFilename(), which should take a filename and return the

* type of file it is (e.g., 'text', 'image', 'video', etc.), based on the

* following extensions:

*

* - .txt, .rtf, .doc, .docx --> 'text'

* - .jpg, .jpeg, .gif, .bmp, .ico, .cur, .png, .svg, .webp --> 'image'

* - .mp3, .wav --> 'audio'

* - .mp4, .webm, .mpeg, .avi --> 'video'

* - .json --> 'data'

* - .csv, .xls --> 'spreadsheet'

* - .ttf, .woff --> 'font'

* - .exe, .dll --> 'binary'

* - .zip --> 'archive'

*

* NOTE: any other extension should return 'unknown', to indicate that it is an

* unknown file type. You should also use 'unknown' if the file has no extension.

*

* @param {string} filename - a filename

* @returns {string}

******************************************************************************/

function typeFromFilename(filename) {

// Replace this comment with your code...

// NOTE: Use a switch statement in your solution.

}

/*******************************************************************************

* Problem 8: generate badge text and link from license code.

*

* Images, videos, and other resources on the web are governed by copyright.

* Everything you find on the web is copyright to its creator automatically, and

* you cannot reuse it unless you are granted a license to do so.

*

* Different licenses exist to allow creators to share their work. For example,

* the Creative Commons licenses are a popular way to allow people to reuse

* copyright material, see https://creativecommons.org/licenses/.

*

* Below is a list of license codes, and the associated badge text explaining the code:

*

* Code License Name

* ----------------------------------------------------------------------------

* CC-BY: Creative Commons Attribution License

* CC-BY-NC: Creative Commons Attribution-NonCommercial License

* CC-BY-SA: Creative Commons Attribution-ShareAlike License

* CC-BY-ND: Creative Commons Attribution-NoDerivs License

* CC-BY-NC-SA: Creative Commons Attribution-NonCommercial-ShareAlike License

* CC-BY-NC-ND: Creative Commons Attribution-NonCommercial-NoDerivs License

*

* NOTE: any other licenseCode should use the URL https://choosealicense.como-permission/

* and the explanation text, "All Rights Reserved"

*

* Write a function, generateLicenseBadge(), which takes a license code string, and returns

* an HTML link to the appropriate badge (i.e., image) URL, including the badge text.

*

* For example:

*

* generateLicenseBadge('CC-BY-NC') should return the following HTML string:

*

* 'Problem 7: determine file type from a filename *'

*

* The URL is generated based on the license code:

*

* - remove the `CC-` prefix

* - convert to rest to lower case

* - create a license URL using the formatted code: https://creativecommons.org/licenses/[...here]/4.0/

* - create a badge image URL using the formatted code: https://licensebuttons.net/l/[...here]/4.0/88x31.png

* - create an and tag, using the license name as alt text

*

* You can read more about HTML image links at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img

*

* @param {string} licenseCode - a license code

* @returns {string}

******************************************************************************/

function generateLicenseBadge(licenseCode) {

// Replace this comment with your code...

}

/*******************************************************************************

* Problem 9: Count the number of true and false values in a dataset

*

* A dataset contains fields that indicate a value is true or false. However,

* users have entered data in various formats and languages (English and French)

* over the years, and the data is a mess. For example, the dataset contains all

* of the following values:

*

* "True" values include: Yes, yes, YES, Y, Oui, oui, OUI, O, t, TRUE, true, True,

* vrai, V, VRAI, 1, 2, ...any positive number

*

* "False" values include: No, no, NO, Non, non, NON, N, n, f, FALSE, false, False,

* FAUX, faux, Faux, 0, -1, -2, ...any negative number

*

* Write two functions that work in similar ways: countTrue() and countFalse()

* both take any number of string, number, or boolean values and count the

* number of items that are either "true" or "false", according to the following rules:

*

* 1. If the value is already a Boolean (true or false) count it as true or false respectively

* 2. If the value is one of the "true" type values, count it as true

* 3. If the value is one of the "false" type values, count it as false

* 4. If the value is none of the "true" or "false" values, ignore it

*

* Your countTrue() and countFalse() functions will have a lot of similarities.

* Write a third function that can be re-used by countTrue() and countFalse()

* to do the common part of this operation. You shouldn't copy/paste any

* code or share much logic between countTrue() and countFalse().

*

* @param {string|number|boolean} data - any number of strings, numbers, or booleans

* @returns {number} - a count of true/false values (depending on which function)

******************************************************************************/

function countTrue(...values) {

// Replace this comment with your code...

}

function countFalse(...values) {

// Replace this comment with your code...

}

/*******************************************************************************

* Problem 10 - build a query string

*

* Querying a web data API involves formatting a query string in a particular way.

* As we know from week 1, a query string is a set of name=value pairs, that starts

* with the ? character, and each pair is separated by the & character, see:

* https://web222.ca/weeks/week01/#query-strings

*

* For example:

*

* ?q=dog&sort=ascending includes q=dog and sort=ascending

* ?_encoding=UTF8&node=18521080011 includes both _encoding=UTF8 and also node=18521080011

*

* Write a buildQueryString() function to build a query string based on arguments

* passed by the caller.

*

* The buildQueryString() function accepts the following arguments:

*

* - queryTerm: a search string, for example "butterfly" or "Horse-chestnut"

* - sortOrder: a string indicating sort order, with possible values of `ascending` or `descending`

* - count: a number from 10 to 200, indicating how many results to return per page

*

* Write an implementation of buildQueryString() that accepts arguments for all of the above

* parameters, validates and formats them (e.g., encode the query, count must be between 10

* and 200, etc), and returns a properly formatted query string.

*

* For example:

*

* buildQueryString('Monarch Butterfly', 'ascending', 25) would return the following query string:

*

* '?query_term=Monarch%20Butterfly&count=25

*

* NOTE: the default sort order is ascending, so it isn't included. However, if we were to

* specify 'descending', it would need to get added:

*

* buildQueryString('Monarch Butterfly', 'descending', 25) would return the following query string:

*

* '?query_term=Monarch%20Butterfly&count=25&descending

*

* NOTE: if any of the values passed to buildQueryString() are invalid, an Error should be thrown.

*

* NOTE: make sure you properly encode the query value, since query strings can't contain

* spaces or other special characters. HINT: use the encodeURIComponent() function

* to do this, see:

*

* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

*

* @param {string} queryTerm the query to use.

* @param {string} sortOrder the sort order to use, must be one of `ascending` or `descending`

* @param {number} count the number of results per page, must be 10-200

* @returns {string} the properly formatted query string

******************************************************************************/

function buildQueryString(queryTerm, sortOrder, count) {

// Replace this comment with your code...

}

// Our unit test files need to access the functions we defined

// above, so we export them here.

exports.greeting = greeting;

exports.toCamelCase = toCamelCase;

exports.createMetaTag = createMetaTag;

exports.parseDateString = parseDateString;

exports.toDateString = toDateString;

exports.normalizeDuration = normalizeDuration;

exports.formatDurations = formatDurations;

exports.typeFromFilename = typeFromFilename;

exports.generateLicenseBadge = generateLicenseBadge;

exports.countTrue = countTrue;

exports.countFalse = countFalse;

exports.buildQueryString = buildQueryString;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!