https://github.com/thiagodroz/oh-my-lib
This is a library of Javascript functions created with the purpose of practicing my Javascript skills and putting into practice some less used techniques.
https://github.com/thiagodroz/oh-my-lib
es6 javascript library npm webpack
Last synced: 2 months ago
JSON representation
This is a library of Javascript functions created with the purpose of practicing my Javascript skills and putting into practice some less used techniques.
- Host: GitHub
- URL: https://github.com/thiagodroz/oh-my-lib
- Owner: thiagodroz
- License: mit
- Created: 2017-09-22T04:08:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-16T03:17:18.000Z (almost 8 years ago)
- Last Synced: 2025-09-21T21:52:52.885Z (10 months ago)
- Topics: es6, javascript, library, npm, webpack
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/oh-my-lib
- Size: 126 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Oh My Lib
[](https://travis-ci.org/thiagodroz/oh-my-lib) [](https://codeclimate.com/github/thiagodroz/oh-my-lib/maintainability) [](https://codeclimate.com/github/thiagodroz/oh-my-lib/test_coverage) []() []()
---
This is a library of Javascript functions created with the purpose of practicing my Javascript skills and putting into practice some less used techniques. Therefore, not all functions are done in a way that has the best possible performance because they may have been done by focusing on a specific approach for study purposes.
---
## Functions categories:
- [Math](#math-functions)
- [Array](#array-functions)
- [Collection](#collection-functions)
---
## Math functions
### max
Called to biggest between two passed values.
**Input**: (*number/string*, *number/string*)
**Output**: *number/string*
```javascript
const result = max(5, 2);
//result == 5
```
### min
Called to smaller between two passed values.
**Input**: (*number/string*, *number/string*)
**Output**: *number/string*
```javascript
const result = min(5, 2);
//result == 2
```
### sumAllInRange
Returns the sum of all integers between the first and the second parameters. If passed a third parameter, the result the result will be the sum of numbers starting from the first parameter but steping the passed value until reach the second parameter.
**Input**: (*integer*, *integer*, *integer=1*)
**Output**: *number*
```javascript
const result = sumAllInRange(3, 99, 4);
//result == 1275
```
---
## Array functions
### first
Return the first element of the array
**Input**: (*array*)
**Output**: *number/string*
```javascript
const result = first([1,2,3]);
//result == 1
```
### tail
Return the the array without the first element
**Input**: (*array*)
**Output**: *array*
```javascript
const result = tail([1,2,3]);
//result == [2,3]
```
### last
Return the last element of the array
**Input**: (*array*)
**Output**: *number/string*
```javascript
const result = last([1,2,3]);
//result == 3
```
### init
Return the the array without the last element
**Input**: (*array*)
**Output**: *array*
```javascript
const result = init([1,2,3]);
//result == [1,2]
```
### each
Called to execute some passed function over all elements of a passed array without return any result.
**Input**: (*array*, *function*)
**Output**: *undefined*
```javascript
each([1,2,3], (value) => { console.log(value) });
```
### filter
Returns as result a list with the elements that passed the test defined by the passed function.
**Input**: (*array*, *function*)
**Output**: *array*
```javascript
filter([1,2,3], (value) => { return value > 1 });
//result == [2,3]
```
### maxOfList
Called to get the biggest value between the values of a passed array.
**Input**: (*array*)
**Output**: *number/string*
```javascript
const result = lib.maxOfList([5,10,2,9]);
//result == 10
```
### maxOccurrence
Called to get the most frequent element of the array. If more than one element have the same frenquency, the first element to reach that frequency will be returned.
**Input**: (*array*)
**Output**: *number/string*
```javascript
const result = lib.maxOccurrence(['a','a','c','b','c','c']);
//result == 'c'
```
### trueValues
Returns a copy of the passed array without the falsy values. In Javascript, the falsy values are false, null, 0, "", undefined and NaN.
**Input**: (*array*)
**Output**: *array*
```javascript
const result = lib.trueValues(['c', 0, null, 1]);
//result == ['c', 1]
```
### except
Returns a copy of the passed array without the passed values.
**Input**: (*array*, *number/string*...)
**Output**: *array*
```javascript
const result = lib.except(['a','a','c','b','c','c'], 'b', 'c');
//result == ['a', 'a']
```
---
## Collection functions
### extractProperty
Called to get the value of a property with the given name of all elements of a passed larrayist.
**Input**: (*array*, *string*)
**Output**: *array*
```javascript
const list = [
{ a: 1, b: 2, c: 3 },
{ a: 4, b: 5, c: 6 },
{ a: 7, b: 8, c: 9 },
{ a: 10, b: 11, c: 12 },
{ a: 13, b: 14, c: 15 }
];
const result = lib.extractProperty(list, 'b');
//result == [2,5,8,11,14]
```
### maxOfProperty
Called to get the biggest value of a passed property from a passed array of objects.
**Input**: (*array*, *string*)
**Output**: *number/string*
```javascript
const result = maxOfProperty([
{ age: 20 },
{ age: 25 },
{ age: 10 },
{ age: 40 }
], 'age');
//result == 40
```