Skip to content

Commit

Permalink
v 1.1.0
Browse files Browse the repository at this point in the history
Add new functions in math module:
- nearestDistance (Finding the nearest position in latitude and longitude)

Not included in the native Math class by default:
- DEG_TO_RAD
- HAV
- AHAV
- CENTRAL_ANGLE
  • Loading branch information
rah-emil committed Aug 13, 2021
1 parent 3323836 commit 35329e8
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 333 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# jsHelpers :tw-1f4af:
# jsHelpers 🚀
jsHelpers - it is a JavaScript library that contains all the functions that we constantly write or google.

Let's use the jsHelpers library to google less and implement more of the project's functionality.
Expand All @@ -22,7 +22,7 @@ Number.prototype.simplifyNumber = simplifyNumber

### CDN
```html
<script src="https://cdn.jsdelivr.net/npm/@rah-emil/js-helpers@1.0.1/dist/js-helpers.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@rah-emil/js-helpers@1.1.0/dist/js-helpers.js"></script>

<script>
(3568934).simplifyNumber(2) // 3.57M
Expand Down Expand Up @@ -60,6 +60,33 @@ Math.randomInteger(10, 90) // random number from 10 to 90
(14.7).isInteger() // false
```

#### The nearest distance
For example, to find the closest city to a user
```javascript

let locations = [
{name: "Moscow", coords: [55.79749504565197, 37.5407153847656]},
{name: "Voronezh", coords: [51.66109513550912, 39.19964245473753]},
{name: "Yaroslavl", coords: [57.62662119485742, 39.89367465100093]},
{name: "Rybinsk", coords: [58.04855727216249, 38.85813673976128]},
{name: "Ivanovo", coords: [57.00040249293972, 40.973840485275254]},
{name: "Kursk", coords: [51.73096145146215, 36.192820361190755]},
{name: "Bryansk", coords: [53.243644660620774, 34.36328412094874]},
]

let myCoords = [52.7614485, 35.6722916]

Math.nearestDistance(locations, myCoords)

// {
// "name": "Bryansk",
// "coords": [
// 53.243644660620774,
// 34.36328412094874
// ]
// }
```

## Converting numbers to a specific format
Very often we need to convert a number, for example, to a monetary format, or just break it down into digits. More on this below.

Expand Down
174 changes: 0 additions & 174 deletions README_RU.md

This file was deleted.

24 changes: 12 additions & 12 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
<script src="js-helpers.js"></script>

<script>
let product = {
title: 'iPhone XR',
// ...
reviews: [
{text: '...', stars: 4.9},
{text: '...', stars: 3.2},
{text: '...', stars: 1},
{text: '...', stars: 5},
{text: '...', stars: 4.5},
]
}
let locations = [
{name: "Moscow", coords: [55.79749504565197, 37.5407153847656]},
{name: "Voronezh", coords: [51.66109513550912, 39.19964245473753]},
{name: "Yaroslavl", coords: [57.62662119485742, 39.89367465100093]},
{name: "Rybinsk", coords: [58.04855727216249, 38.85813673976128]},
{name: "Ivanovo", coords: [57.00040249293972, 40.973840485275254]},
{name: "Kursk", coords: [51.73096145146215, 36.192820361190755]},
{name: "Bryansk", coords: [53.243644660620774, 34.36328412094874]},
]

let myCoords = [52.7614485, 35.6722916]

console.log(product.reviews.average('stars'))
console.log(Math.nearestDistance(locations, myCoords))
</script>
</body>
</html>
Loading

0 comments on commit 35329e8

Please sign in to comment.