Question: Question : Count the number of true and false values in a dataset * * A dataset contains fields that indicate a value is true
Question : 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...
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
