Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ejercicios Resueltos Tarea Programación Funcional 1 #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 66 additions & 10 deletions src/ejercicios.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,75 @@
export function multiplicarPor10(array) {}
export function multiplicarPor10(array) {
return array.map(element => element * 10)
}

export function soloPares(array) {}
export function soloPares(array) {
return array.filter(element => element % 2 === 0)
}

export function moverALaDerecha(array) {}
export function moverALaDerecha(array) {
const arrayCopy = [...array];

export function soloUnaPalabra(array) {}
return arrayCopy.map((element, index, arr) => {
return index ? arr[index - 1] : index === 0 ? arr[arr.length - 1] : "";
})
}

export function soloArraysPositivos(array) {}
export function soloUnaPalabra(array) {
return array.filter(element => !element.includes(" "))
}

export function soloVocales(array) {}
export function soloArraysPositivos(array) {
return array.filter(element => element.every(item => item > 0))
}

export function todasVocalesIguales(array) {}
export function soloVocales(array) {
const rex = /[bcdfghjkmnlpqrstqvwxyz]/;
return array.map(element => {
return element.split("").map(item => {
if (rex.test(item)) {
item = ""
} else {return item}
}).join("")
})
}

export function duplicarMatriz(array) {}
export function todasVocalesIguales(array) {
const rex = /[aeiou]/
const checkforSameVocals = (word) => {
const wordSplit = [...word]
const vocalsMapped = wordSplit.filter(letter => {
return rex.test(letter)
})
return vocalsMapped.every((item, _index, arr) => item === arr[0])
}

return array.filter(element => {
return checkforSameVocals(element)
})
}

export function mayoresDeEdadValidados(array) {}
export function duplicarMatriz(array) {
return array.map(element => {
return element.map(item => {
return item * 2
})
})
}

export function transformarObjetoEnArray(objeto) {}
export function mayoresDeEdadValidados(array) {
return array.map(element => {
if (element.edad > 18) {
element.mayor = true;
} else {
element.mayor = false;
}
return element
})
}

export function transformarObjetoEnArray(objeto) {
const objectToArray = Object.entries(objeto)
return objectToArray.map(element => {
return Object.assign({id: element[0]}, element[1])
})
}