Write ten functions that are useful in some way, and demonstrate their use both by calling them directly and by passing them to Array iteration methods like .map(), .forEach(), .filter(), .reduce(), .every().
The only way to write better code is to write more code. In this exercise, you'll write at minimum ten different functions and use them in some way.
Here are a few ideas:
- upperCase(string): Return
stringin all CAPITAL LETTERS. - lowerCase(string): Return
stringin all lowercase letters. - capitalize(string): Return
stringwith the first letter Capitalized. - sentenceCase: Return
stringwith the first letter capitalized, and convert the rest of the string to lowercase. - titleCase(string): Return
stringwith Every Word Capitalized. - camelCase(string): Return
stringconverted to camelCase by capitalizing all words but the first, and removing all non-word characters (everything but a–z, A–Z, 0–9, and _ (underscore)). For example: "Bermuda Love Triangle is Awesome!!" would be converted to "bermudaLoveTriangleIsAwesome". - snakeCase(string): Return
stringconverted to "snake_case": separate out all "camelCased" words, lowercase all characters, and replace non-word characters (or multiple non-word characters) with a single underscore. Remove beginning or trailing underscores. - kebobCase(string): Return
stringconverted to "snake_case": separate out all "camelCased" words, lowercase all characters, and replace non-word characters (or multiple non-word characters) with a hyphen (-). Remove beginning or trailing underscores.
- range(start, end, step): Return an Array of numbers (positive and/or negative) progressing from
startup to, but not including,end. Increment bystepif provided, or1if not. Ifendis less thanstart, a zero-length range is created unless a negativestepis specified. - largest: Return the greater of two numbers
- smallest: Return the smaller of two numbers
- constant(value): Return a function that ALWAYS returns a specific value
- is(value): Return a function that returns
truewhen passed something strictly equal tovalue, andfalsewhen passed something other thanvalue. - greaterThan(n): Return a function that returns
truewhen passed a number greater thanvalue, andfalsewhen passed something equal to or smaller thanvalue. - greaterThanOrEqualTo(n): Return a function that returns
truewhen passed a number greater than or equal tovalue, andfalsewhen passed something smaller thanvalue. - lessThan(n): Return a function that returns
truewhen passed a number less thanvalue, andfalsewhen passed something equal to or greater thanvalue. - lessThanOrEqualTo(n): Return a function that returns
truewhen passed a number less or equal tovalue, andfalsewhen passed something greater thanvalue. - noop(): Define a function that takes no parameters, has no method body, and returns nothing.
- compose(fn1, fn2[, ...fnN]): Return a new function such that
compose(fn1, fn2)(1, 2)is the same asfn1(fn2(1, 2)). - pipe(fn1[, fn1[, ...fnN]): Return a function that, when executed, passes its arguments