-
Notifications
You must be signed in to change notification settings - Fork 8
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
ecf096a
commit d3a1e74
Showing
2 changed files
with
52 additions
and
0 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
18 changes: 18 additions & 0 deletions
18
app/javascript/multi-stamp-tubes/components/tubeFunctions.js
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,18 @@ | ||
/* Given a list of items and an element, reduce the list to a unique set of items, and return the new idex of the provided element. | ||
* @param {Array} items - The list of items to reduce. | ||
* @param {Object} element - The element to find the unique index of. | ||
* @returns {Number} - The unique index of the provided index. | ||
* @example - findUniqueIndex([5, 1, 2, 1, 2, 3], 0) => -1 | ||
* @example - findUniqueIndex([5, 1, 2, 1, 2, 3], 1) => 0 | ||
* @example - findUniqueIndex([5, 1, 2, 1, 2, 3], 2) => 1 | ||
* @example - findUniqueIndex([5, 1, 2, 1, 2, 3], 3) => 2 | ||
* @example - findUniqueIndex([5, 1, 2, 1, 2, 3], 4) => -1 | ||
* @example - findUniqueIndex([5, 1, 2, 1, 2, 3], 5) => 3 | ||
* @example - findUniqueIndex([5, 1, 2, 1, 2, 3], 6) => -1 | ||
*/ | ||
const findUniqueIndex = (items, element) => { | ||
const uniqueItems = [...new Set(items)] | ||
return uniqueItems.indexOf(element) | ||
} | ||
|
||
export { findUniqueIndex } |