-
Notifications
You must be signed in to change notification settings - Fork 0
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
689d3a8
commit 354f0fc
Showing
3 changed files
with
10 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
package-lock.json | ||
package.json |
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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
/* eslint-disable space-before-function-paren */ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
// 1 - iterar cada numero | ||
// 2 - chequeo si el numero esta en el mapa | ||
// 3 - retorno el que de true | ||
|
||
function findFirstRepeated(gifts) { | ||
const set = new Set() | ||
const list = [] | ||
|
||
for (const gift of gifts) { | ||
if (set.has(gift)) { | ||
if (list.includes(gift)) { | ||
return gift | ||
} | ||
|
||
set.add(gift) | ||
list.push(gift) | ||
} | ||
|
||
return -1 | ||
} | ||
|
||
const gifts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 4] | ||
const gifts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 6] | ||
|
||
// console.log(findFirstRepeated(gifts)) |
File renamed without changes.