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

Promocion 2024 mayo paco prework #28

Open
wants to merge 10 commits into
base: promocion-2024-mayo
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
14 changes: 14 additions & 0 deletions prework/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Recorre y suma todos los números de este array

function arraySum(array) {
const flatNumbersArray = array.flat();
return flatNumbersArray.reduce((acc, cur) => acc + cur, 0);
}

let array = [
[2, 2],
[3, 4],
[1, 1, 1],
];

arraySum(array);
18 changes: 18 additions & 0 deletions prework/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Escribe una función que dados un array y una longitud `size`
// divida la lista en múltiples subarrays de longitud `size`


function chunk(array, size) {
const result = [];
for (let i = 0; i < array.length; i += size) {
result.push(array.slice(i, i + size))
}
return result;
}

// Ejemplos
chunk([1, 2, 3, 4], 2); // === [[ 1, 2], [3, 4]]
chunk([1, 2, 3, 4, 5], 2); // === [[ 1, 2], [3, 4], [5]]
chunk([1, 2, 3, 4, 5, 6, 7, 8], 3); // === [[ 1, 2, 3], [4, 5, 6], [7, 8]]
chunk([1, 2, 3, 4, 5], 4); // === [[ 1, 2, 3, 4], [5]]
chunk([1, 2, 3, 4, 5], 10); // === [[ 1, 2, 3, 4, 5]]
15 changes: 15 additions & 0 deletions prework/contadorIncremental.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

const incrementalCounter = (initialValue = 0) => {
let value = initialValue;
const increase = () => value += 1;
const print = () => console.log(value);

const doWork = () => {
increase();
print();
}

setInterval(doWork, 1000);
}

incrementalCounter();
9 changes: 9 additions & 0 deletions prework/extractNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Crea una función que extraiga los números de una string con el formato provisto
function extractNumbers(inputString) {
return inputString
.split(' ')
.map(splittedString => parseInt(splittedString))
.filter(possibleNumber => possibleNumber);
}

extractNumbers("3 20 6 1"); // [3, 20, 6, 1]
7 changes: 7 additions & 0 deletions prework/getEven.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Crea una función que devuelva los números pares

function getEven(nums) {
return nums.filter(num => num % 2 === 0);
}

getEven([1, 2, 3, 4, 5]); // [2, 4]
6 changes: 6 additions & 0 deletions prework/getWords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Crea una función que separe las palabras de una frase
function getWords(words) {
return words.split(' ');
}

getWords("lorem ipsum dolor"); // ["lorem", "ipsum", "dolor"]
8 changes: 8 additions & 0 deletions prework/max.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Crea una función que devuelva el número máximo
// No utilizes Math.Max ni similares

function max(nums) {
return nums.reduce((acc, cur) => cur > acc ? cur : acc, 0)
}

max([2, 4, 6, 8]); // 8
37 changes: 37 additions & 0 deletions prework/pyramid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Escribe una función que reciba un número positivo N
// La función debe imprimir una pirámide de simbolos #
// Con N niveles


function pyramid(N) {
const SYMBOL = '#';
const SPACE = ' ';
const width = N * 2 - 1;
const spaces = [...Array(N).keys()].reverse();

spaces
.forEach(lineSpaces => {
const SYMBOL_WIDTH = width - lineSpaces * 2;
const spaceString = SPACE.repeat(lineSpaces);
const symbolString = SYMBOL.repeat(SYMBOL_WIDTH);
const line = `${spaceString}${symbolString}${spaceString}`
console.log(line)
})
}


// Ejemplos
pyramid(1);
// "#"

pyramid(2);
// " # "
// "###"

pyramid(3);
// " # "
// " ### "
// "#####"


pyramid(15);
6 changes: 6 additions & 0 deletions prework/removeSpaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Crea una función que elimine todos los espacios de una frase
function removeSpaces(words) {
return words.replaceAll(' ', '');
}

removeSpaces("lorem ipsum dolor"); // "loremipsumdolor"
7 changes: 7 additions & 0 deletions prework/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Crea una función que devuelva la suma total

function sum(nums) {
return nums.reduce((acc, cur) => acc + cur, 0);
}

sum([1, 2, 3, 4, 5]); // 15