challenge 8 #30

Open
opened 2022-04-14 16:36:16 +02:00 by nestor-almarza · 2 comments
nestor-almarza commented 2022-04-14 16:36:16 +02:00 (Migrated from github.com)

const miLista =
["Lisp", "Clojure", "Haskell", "Elm", "Racket", "Swift", "Erlang", "Scala"]

/**
*

  • @param {*} current
  • @param {*} destination
  • @param {*} array
  • @returns
    */
    const moverElemento = (current ,destination , array) => {
    if( !Number.isInteger(current) || !Number.isInteger(destination)){
    return "Las posiciones deben ser números."}
    if(current < 0 || destination < 0){ return "Esa posicón no es válida." }
    if( current === destination ){ return array}
    if(array.length < destination || array.length < current){
    return "Parece que esa posición no existe."}
    // new array without the element that is about to be relocated
    const newArr = array.filter((element, index) => index !== current);
    // new array with current added in it
    newArr.splice(destination, 0, array[current]);
    return newArr;
    }
    console.log(moverElemento(0, 3, miLista))
const miLista = ["Lisp", "Clojure", "Haskell", "Elm", "Racket", "Swift", "Erlang", "Scala"] /** * * @param {*} current * @param {*} destination * @param {*} array * @returns */ const moverElemento = (current ,destination , array) => { if( !Number.isInteger(current) || !Number.isInteger(destination)){ return "Las posiciones deben ser números."} if(current < 0 || destination < 0){ return "Esa posicón no es válida." } if( current === destination ){ return array} if(array.length < destination || array.length < current){ return "Parece que esa posición no existe."} // new array without the element that is about to be relocated const newArr = array.filter((element, index) => index !== current); // new array with current added in it newArr.splice(destination, 0, array[current]); return newArr; } console.log(moverElemento(0, 3, miLista))
tanrax commented 2022-04-19 11:02:42 +02:00 (Migrated from github.com)

Buen trabajo @nestor-almarza!

Buen trabajo @nestor-almarza!
tanrax commented 2022-04-19 11:06:14 +02:00 (Migrated from github.com)

¡Envíame un mensaje privado por Twitter (@androsfenollosa) con tu nombre, apellidos y email; para que te pueda dar el título! :)
¡Estás aprobado!

¡Envíame un mensaje privado por Twitter (@androsfenollosa) con tu nombre, apellidos y email; para que te pueda dar el título! :) ¡Estás aprobado!
Sign in to join this conversation.