JSFiddle - React, Tailwind, and code Playground
by Sergey Shaliapin
JavaScript
// © EPAM JS lab 2016
// Data types, functions, arrays.
// We have an array with mixed primitive values
var arrayMixed = [12, 12, 12, "12", 5, "right", "straight", "fight", true, true, !"", !0, null];
// Task: Create function that returns number of values
function numberOfValues(arrayMixed, value) {
// your code here
};
// tips
// If it is number - compare with each number value
numberOfValues(arrayMixed, 12); // shows 3
// If it is string - check if the string is a part of each value
numberOfValues(arrayMixed, "ght"); // shows 3
// If it is boolean - check true or false
numberOfValues(arrayMixed, true); // shows 4
// If it is null / undefined - check null / undefined
numberOfValues(arrayMixed, null); // shows 1
// Careful: 12 !== "12", check this case
// * Additional task: Create function that separates array of values
function arraySeparator(arrayMixed, value, boolean) {
// your code here
};
// If pass true parameter - make new array with equal values
var existValues = arraySeparator(arrayMixed, 12, true);
// existValues === [12, 12, 12]
// If pass false parameter - make new array with not values
var notExistValues = arraySeparator(arrayMixed, "ght", false);
// notExistValues === [12, 12, 12, 12, 5, true, true, !"", !0, null]