jsmp-infra-first-task
v2.0.3
Published
package of different js functions
Downloads
1
Readme
npm module for first task
Js code.
Package
You can find a package details npm.
# With npm
npm install jsmp-infra-first-task
Usage examples
// ES Modules
import {all} from 'jsmp-infra-first-task';
all([4, 2, 3], x => x > 1); // true
To import snippets with Node:
const all = require('jsmp-infra-first-task').all;
all([4, 2, 3], x => x > 1);
const {all} = require('jsmp-infra-first-task').all;
all([4, 2, 3], x => x > 1);
Table of Contents
Array
String
Array
all
Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.
Use Array.every() to test if all elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.
const all = (arr, fn = Boolean) => arr.every(fn);
all([1, 2, 3]); // true ]
any
Returns true if the provided predicate function returns true for at least one element in a collection, false otherwise.
Use Array.some() to test if any elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.
const any = (arr, fn = Boolean) => arr.some(fn);
any([0, 1, 2, 0], x => x >= 2); // true
String
isLowerCase
Checks if a string is lower case.
Convert the given string to lower case, using String.toLowerCase() and compare it to the original.
const isLowerCase = str => str === str.toLowerCase();
isLowerCase('abc'); // true
isLowerCase('a3@$'); // true
isLowerCase('Ab4'); // false