-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b03291f
commit 7cb6261
Showing
6 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function groupBy(arr, predicate) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return arr.reduce((obj, item) => { | ||
// Check if the predicate is a function to run on the item or a property of it | ||
const key = predicate | ||
? typeof predicate === 'function' | ||
? predicate(item) | ||
: item[predicate] | ||
: item; | ||
|
||
if (obj && !obj.hasOwnProperty(key)) { | ||
obj[key] = []; | ||
} | ||
|
||
// Push the value to the object | ||
obj[key].push(item); | ||
|
||
// Return the object to the next item in the loop | ||
return obj; | ||
}, {}); | ||
} | ||
|
||
export default groupBy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const keyControl = (keys, key) => { | ||
for (const item in keys) { | ||
if (Array.isArray(keys[item])) { | ||
const arrayStatus = keyControl(keys[item], key); | ||
if (!arrayStatus) { | ||
return false; | ||
} | ||
} | ||
if (keys[item] === key) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
function omit(obj, ...keys) { | ||
return Object.fromEntries(Object.entries(obj).filter(([k]) => keyControl(keys, k))); | ||
} | ||
|
||
export default omit; |
Bu function hali hazirda utils/struct altinda var diye hatirliyorum. Diger kullanan yerleri de duruma gore duzeltmek gerekebilir. Ek olarak buraya lodash/groupBy demek yerine baska isim kullanabiliriz.