Skip to content

Commit

Permalink
usar array y instalar standard
Browse files Browse the repository at this point in the history
  • Loading branch information
fernargdev committed Dec 13, 2023
1 parent 689d3a8 commit 354f0fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
package-lock.json
package.json
12 changes: 7 additions & 5 deletions retos/reto-1.js
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.

0 comments on commit 354f0fc

Please sign in to comment.