#Challenge 23

1 messages · Page 1 of 1 (latest)

umbral bough
brittle kettle
#

Hola gente, ¿como habéis hecho este? Paso los tests de los ejemplos, pero no el resto. Y el error que da juraría que es de un reto anterior.

#

¡No pasan los tests! Revisa bien los ejemplos y ten en cuenta que puede haber viajes con más paradas de dos...

still steppe
#

Solución, incorrecta, pero pasa los tests 😅 ||```js
function canReconfigure( from, to ) {
return from.length === to.length &&
[... new Set( from.split('') )].length === [... new Set( to.split('') )].length
}

brittle kettle
#

Yo lo tengo muy parecido, que no igual.
||```js
function canReconfigure(from, to) {
if (from.length !== to.length) return false
if (from.length !== [...new Set([...from])].length) return false
if (to.length !== [...new Set([...to])].length) return false
return true
}

#

La movida es que el tuyo no debería pasar, ¿no? En un caso 'MMX' y 'JAA' estaría mal

#

Actualizado el mío a esto, y ya pasan:
||```js
function canReconfigure(from, to) {
if (from.length !== to.length) return false
if ([...new Set([...from])].length !== [...new Set([...to])].length) return false
return true
}

still steppe
brittle kettle
#

Si si, pero no se si debería ser correcto

still steppe
still steppe
#

En realidad tenía otra solución, más verbosa, pero creo que es correcta. Como dices, ese caso 'MMX', 'JAA', debería de ser false y devuelve true

still steppe
#

Solución que funciona:
||```js
function canReconfigure( from, to ) {
if( from.length !== to.length ) return false

const transformations = {}
for( const i in from ) {
const letterFrom = from[ i ]
const letterTo = to[ i ]

if( transformations[ letterFrom ] && transformations[ letterFrom ] !== letterTo ) return false

const previousTransform = Object
  .entries( transformations )
  .find( ( [ , letter ] ) => letter === letterTo )

if( previousTransform && previousTransform[ 0 ] !== letterFrom ) return false 

transformations[ letterFrom ] = letterTo

}

return true
}```
||

outer lance
#

no es muy bonico pero ahi va

pure flicker
#

No se si he entendido bien los requisitos del reto..
Hay que mirar que ni el FROM ni el TO tenga duplicados, no?
Bueno y que tengan la misma longitud..

sand vortex
#

Mi solución para el reto.

cyan pecan
#

Mi solución

still steppe
gusty haven
fluid pendant
solar ether
#

Mi solución

sand vortex
#

dejo mi solución por aquí también

lime tinsel
#

Reto 23

subtle thistle
#

Reto 23 - No fue fácil

raw orchid
#

Bueno es lo primero que se me ocurrio