Skip to content

Commit 223090e

Browse files
Updated packages. Made a lint. Readme updated.
1 parent 3a99bac commit 223090e

File tree

4 files changed

+59
-46
lines changed

4 files changed

+59
-46
lines changed

.eslintrc.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ module.exports = {
33
env: {
44
browser: true,
55
node: true,
6-
es6: true
6+
es6: true,
77
},
88
parser: "@typescript-eslint/parser",
99
parserOptions: {
10-
"ecmaVersion": 2020,
11-
"sourceType": "module"
10+
ecmaVersion: 2020,
11+
sourceType: "module",
1212
},
1313
plugins: ["@typescript-eslint/eslint-plugin"],
1414
extends: [
1515
"plugin:prettier/recommended",
1616
"eslint:recommended",
17-
"plugin:@typescript-eslint/recommended"
17+
"plugin:@typescript-eslint/recommended",
1818
],
1919
rules: {
2020
"no-console": "off",
2121
"no-unused-vars": "off",
2222
"spaced-comment": "off",
23-
"camelcase": "off"
24-
}
23+
camelcase: "off",
24+
},
2525
}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ const uniqueNames = getUniqueValues(arrayOfObjects, "name")
6464

6565
This function returns an array containing only the unique values of a specific property in the objects. It accepts as parameters first the ArrayOfObjects and second - a string of the property name.
6666

67+
### findFirstOneMatching(arrayOfObjects, propertyName, propertyValue)
68+
69+
### findLastOneMatching(arrayOfObjects, propertyName, propertyValue)
70+
71+
### findAllMatching(arrayOfObjects, propertyName, propertyValue)
72+
73+
### removeFirstOneMatching(arrayOfObjects, propertyName, propertyValue)
74+
75+
### removeLastOneMatching(arrayOfObjects, propertyName, propertyValue)
76+
77+
### removeAllMatching(arrayOfObjects, propertyName, propertyValue)
78+
6779
## Contribution
6880

6981
Everybody can contribute

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@
3434
},
3535
"dependencies": {},
3636
"devDependencies": {
37-
"@babel/cli": "^7.0.0",
38-
"@babel/core": "^7.0.0",
39-
"@babel/plugin-proposal-class-properties": "^7.5.5",
40-
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
41-
"@babel/plugin-transform-modules-umd": "^7.2.0",
42-
"@babel/preset-typescript": "^7.3.3",
43-
"@types/jest": "^24.0.18",
44-
"@typescript-eslint/eslint-plugin": "^2.0.0",
45-
"@typescript-eslint/parser": "^2.0.0",
46-
"babel-jest": "^24.9.0",
47-
"eslint": "^6.2.1",
48-
"eslint-config-prettier": "^6.1.0",
49-
"eslint-config-standard": "^14.0.0",
50-
"eslint-plugin-import": "^2.18.2",
51-
"eslint-plugin-jest": "^22.15.1",
52-
"eslint-plugin-node": "^9.1.0",
53-
"eslint-plugin-prettier": "^3.1.0",
54-
"eslint-plugin-promise": "^4.2.1",
55-
"eslint-plugin-standard": "^4.0.1",
56-
"jest": "^24.9.0",
57-
"prettier": "^1.18.2",
58-
"ts-jest": "^24.0.2",
59-
"typescript": "^3.6.2"
37+
"@babel/cli": "^7.16.8",
38+
"@babel/core": "^7.16.12",
39+
"@babel/plugin-proposal-class-properties": "^7.16.7",
40+
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
41+
"@babel/plugin-transform-modules-umd": "^7.16.7",
42+
"@babel/preset-typescript": "^7.16.7",
43+
"@types/jest": "^27.4.0",
44+
"@typescript-eslint/eslint-plugin": "^5.10.1",
45+
"@typescript-eslint/parser": "^5.10.1",
46+
"babel-jest": "^27.4.6",
47+
"eslint": "^8.8.0",
48+
"eslint-config-prettier": "^8.3.0",
49+
"eslint-config-standard": "^16.0.3",
50+
"eslint-plugin-import": "^2.25.4",
51+
"eslint-plugin-jest": "^26.0.0",
52+
"eslint-plugin-node": "^11.1.0",
53+
"eslint-plugin-prettier": "^4.0.0",
54+
"eslint-plugin-promise": "^6.0.0",
55+
"eslint-plugin-standard": "^4.1.0",
56+
"jest": "^27.4.7",
57+
"prettier": "^2.5.1",
58+
"ts-jest": "^27.1.3",
59+
"typescript": "^4.5.5"
6060
}
6161
}

src/array-of-objects.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ export function getUniqueValues(
44
): Array<any> {
55
const output: Array<any> = []
66

7-
arrayOfObjects.map(obj => {
7+
arrayOfObjects.map((obj) => {
88
if (obj[propertyName] !== undefined) {
99
if (
10-
output.find(val => JSON.stringify(obj[propertyName]) === JSON.stringify(val)) === undefined
10+
output.find((val) => JSON.stringify(obj[propertyName]) === JSON.stringify(val)) ===
11+
undefined
1112
) {
1213
output.push(obj[propertyName])
1314
}
@@ -19,12 +20,12 @@ export function getUniqueValues(
1920

2021
export function findFirstOneMatching(
2122
arrayOfObjects: Record<string, any>[],
22-
propertyName: any,
23+
propertyName: string,
2324
propertyValue: any
2425
): Record<string, any> | null {
2526
let output: Record<string, any> | null = null
2627

27-
arrayOfObjects.some(obj => {
28+
arrayOfObjects.some((obj) => {
2829
if (obj[propertyName] !== undefined) {
2930
if (JSON.stringify(obj[propertyName]) === JSON.stringify(propertyValue)) {
3031
output = obj
@@ -41,12 +42,12 @@ export function findFirstOneMatching(
4142

4243
export function findLastOneMatching(
4344
arrayOfObjects: Record<string, any>[],
44-
propertyName: any,
45+
propertyName: string,
4546
propertyValue: any
4647
): Record<string, any> | null {
4748
let output: Record<string, any> | null = null
4849

49-
arrayOfObjects.map(obj => {
50+
arrayOfObjects.map((obj) => {
5051
if (obj[propertyName] !== undefined) {
5152
if (JSON.stringify(obj[propertyName]) === JSON.stringify(propertyValue)) {
5253
output = obj
@@ -59,12 +60,12 @@ export function findLastOneMatching(
5960

6061
export function findAllMatching(
6162
arrayOfObjects: Record<string, any>[],
62-
propertyName: any,
63+
propertyName: string,
6364
propertyValue: any
6465
): Record<string, any>[] {
65-
let output: Record<string, any>[] = []
66+
const output: Record<string, any>[] = []
6667

67-
arrayOfObjects.map(obj => {
68+
arrayOfObjects.map((obj) => {
6869
if (obj[propertyName] !== undefined) {
6970
if (JSON.stringify(obj[propertyName]) === JSON.stringify(propertyValue)) {
7071
output.push(obj)
@@ -77,12 +78,12 @@ export function findAllMatching(
7778

7879
export function removeFirstOneMatching(
7980
arrayOfObjects: Record<string, any>[],
80-
propertyName: any,
81+
propertyName: string,
8182
propertyValue: any
8283
): Record<string, any>[] {
83-
let flag: boolean = false
84+
let flag = false
8485

85-
return arrayOfObjects.filter(obj => {
86+
return arrayOfObjects.filter((obj) => {
8687
if (obj[propertyName] !== undefined && !flag) {
8788
if (JSON.stringify(obj[propertyName]) === JSON.stringify(propertyValue)) {
8889
flag = true
@@ -97,10 +98,10 @@ export function removeFirstOneMatching(
9798

9899
export function removeLastOneMatching(
99100
arrayOfObjects: Record<string, any>[],
100-
propertyName: any,
101+
propertyName: string,
101102
propertyValue: any
102103
): Record<string, any>[] {
103-
let lastOneMatchingIndex: number = -1
104+
let lastOneMatchingIndex = -1
104105

105106
arrayOfObjects.map((obj, index) => {
106107
if (obj[propertyName] !== undefined) {
@@ -110,7 +111,7 @@ export function removeLastOneMatching(
110111
}
111112
})
112113

113-
let output = JSON.parse(JSON.stringify(arrayOfObjects))
114+
const output = JSON.parse(JSON.stringify(arrayOfObjects))
114115

115116
if (lastOneMatchingIndex != -1) {
116117
output.splice(lastOneMatchingIndex, 1)
@@ -121,10 +122,10 @@ export function removeLastOneMatching(
121122

122123
export function removeAllMatching(
123124
arrayOfObjects: Record<string, any>[],
124-
propertyName: any,
125+
propertyName: string,
125126
propertyValue: any
126127
): Record<string, any>[] {
127-
return arrayOfObjects.filter(obj => {
128+
return arrayOfObjects.filter((obj) => {
128129
if (obj[propertyName] !== undefined) {
129130
if (JSON.stringify(obj[propertyName]) === JSON.stringify(propertyValue)) {
130131
return false

0 commit comments

Comments
 (0)