From ae75ca231a8e431e3be296a09878140d0fc5e84b Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Tue, 3 May 2022 03:11:52 +0200 Subject: [PATCH 1/8] 41 test pasados --- .gitignore | 2 + src/funcArray.js | 116 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 3c3629e..64d5b53 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +.gitignore + diff --git a/src/funcArray.js b/src/funcArray.js index f35b09d..a8e20f6 100644 --- a/src/funcArray.js +++ b/src/funcArray.js @@ -1,16 +1,114 @@ /* Encuentra el máximo */ -export function maxOfTwoNumbers(){} -export function findLongestWord(){} -export function sumArray(){} -export function averageNumbers(){} -export function averageWordLength(){} -export function uniquifyArray(){} -export function doesWordExist(){} -export function howManyTimes(){} -export function greatestProduct(){} +export function maxOfTwoNumbers(num1, num2){ + let mayor = Math.max(num1, num2); + return mayor; +} + +/* Encuentra la palabra mas larga */ +//Forma guay de hacerlo ( con el codigo entendido, no solo copiado) +export function findLongestWord(arrayWords){ + if(arrayWords.length === 0) { + return undefined; + } else { + let longestWord=""; + arrayWords.forEach(word => { + if(word.length > longestWord.length) { + longestWord= word + } + }); + + return longestWord; +} +} +//Forma no tan guay +// export function findLongestWord(arrayWords){ +// let longestWord = ""; +// if(arrayWords.length === 0) { +// return undefined; +// } else { +// for( let i=0; i < arrayWords.length; i++) { +// if(arrayWords[i].length > longestWord.length) { +// longestWord = arrayWords[i]; +// } +// } +// return longestWord; +// } +// } + +/* Calcula la suma */ +//Forma guay de hacerlo ( con el codigo entendido, no solo copiado) +export function sumArray(nombreArray){ +const initialValue = 0 +const sumWithInitial = nombreArray.reduce( + (previousValue, currentValue) => previousValue + currentValue, + initialValue ); + return sumWithInitial +} +//Forma no tan guay + +// export function sumArray(nombreArray){ +// let total =0; +// for( let i= 0; i x.length) + let mediaWords= averageNumbers(largeWords); + return mediaWords; +} +//Unique Arrays +export function uniquifyArray(array){ + if(array.length === 0) { + return undefined; + } else { let resultado = array.reduce((palabraSinRepetir, currentValue) =>{ + + if(!palabraSinRepetir.find(d => d == currentValue)) { + palabraSinRepetir.push(currentValue) + } + return palabraSinRepetir; + }, []) + + return resultado + + } +} +// Busca elementos +export function doesWordExist(array,buscar){ + if(array.find(buscar)) { + return true; + } else { + return false; + } +} +//Cuenta repeticiones +export function howManyTimes(array,buscar){ + let exist = doesWordExist(array,buscar); + if( exist == false) { + return undefined; + } else { + return array.reduce((a, c) => (a[c] ? a[c] += 1 : a[c]=1, a), {}); + } +} +export function greatestProduct(){} + From c34daac103343bc16a43932bbcef29096ce3bd34 Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Tue, 3 May 2022 11:14:30 +0200 Subject: [PATCH 2/8] modificaciones de clase --- src/funcArray.js | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/funcArray.js b/src/funcArray.js index a8e20f6..d8467ff 100644 --- a/src/funcArray.js +++ b/src/funcArray.js @@ -6,7 +6,7 @@ export function maxOfTwoNumbers(num1, num2){ } /* Encuentra la palabra mas larga */ -//Forma guay de hacerlo ( con el codigo entendido, no solo copiado) +//Forma 1 de resolver export function findLongestWord(arrayWords){ if(arrayWords.length === 0) { return undefined; @@ -21,7 +21,7 @@ export function findLongestWord(arrayWords){ return longestWord; } } -//Forma no tan guay +//Forma 2 de resolver // export function findLongestWord(arrayWords){ // let longestWord = ""; // if(arrayWords.length === 0) { @@ -60,13 +60,10 @@ const sumWithInitial = nombreArray.reduce( /*Calcula la media aritmética*/ //Array de Números export function averageNumbers(nombreArray){ - if(nombreArray.length === 0) { + if(!nombreArray.length) return undefined; - } else { - let suma = sumArray(nombreArray) - let media = suma/nombreArray.length - return media - } + return sumArray(nombreArray)/nombreArray.length + } // Array of Strings export function averageWordLength(array){ @@ -91,24 +88,10 @@ export function uniquifyArray(array){ } } // Busca elementos -export function doesWordExist(array,buscar){ - if(array.find(buscar)) { - return true; - } else { - return false; - } -} +export function doesWordExist(array,buscar){} //Cuenta repeticiones -export function howManyTimes(array,buscar){ - let exist = doesWordExist(array,buscar); - if( exist == false) { - return undefined; - } else { - return array.reduce((a, c) => (a[c] ? a[c] += 1 : a[c]=1, a), {}); - } -} +export function howManyTimes(){} export function greatestProduct(){} - From 0c0ce44e137200430ef8b8169293f9e84d1241b6 Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Tue, 3 May 2022 23:11:11 +0200 Subject: [PATCH 3/8] solo falta el ultimo --- src/funcArray.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/funcArray.js b/src/funcArray.js index d8467ff..9e68236 100644 --- a/src/funcArray.js +++ b/src/funcArray.js @@ -88,9 +88,23 @@ export function uniquifyArray(array){ } } // Busca elementos -export function doesWordExist(array,buscar){} +export function doesWordExist(array,buscar){ + if(array.includes(buscar)) + return true; + return false; +} //Cuenta repeticiones -export function howManyTimes(){} +export function howManyTimes(array,buscar){ + if(!array.length) { + return undefined; + } else {let contador= 0; + array.forEach(element => { + if(element.includes(buscar)){ + contador ++ + } + }); + return contador;} + } export function greatestProduct(){} From 0b07c68c6886668678d636173172e040fad83f94 Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Fri, 6 May 2022 11:24:20 +0200 Subject: [PATCH 4/8] el ultimo pass bien puesto --- src/funcArray.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/funcArray.js b/src/funcArray.js index 9e68236..24e3248 100644 --- a/src/funcArray.js +++ b/src/funcArray.js @@ -37,14 +37,14 @@ export function findLongestWord(arrayWords){ // } /* Calcula la suma */ -//Forma guay de hacerlo ( con el codigo entendido, no solo copiado) +//Forma guay de hacerlo export function sumArray(nombreArray){ -const initialValue = 0 const sumWithInitial = nombreArray.reduce( - (previousValue, currentValue) => previousValue + currentValue, - initialValue ); +(previousValue, currentValue) => previousValue + currentValue, + 0 ); return sumWithInitial } + //Forma no tan guay // export function sumArray(nombreArray){ From 958a6f3e5003fd38c25e81cf7ec43da7ad5a56bc Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Fri, 6 May 2022 11:54:24 +0200 Subject: [PATCH 5/8] actualizada la kata --- src/funcArray.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/funcArray.js b/src/funcArray.js index 24e3248..40affaa 100644 --- a/src/funcArray.js +++ b/src/funcArray.js @@ -71,6 +71,7 @@ export function averageWordLength(array){ let mediaWords= averageNumbers(largeWords); return mediaWords; } + //Unique Arrays export function uniquifyArray(array){ if(array.length === 0) { From 6fe953681fa2e392eafab0e37855f8c060c08745 Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Sun, 8 May 2022 21:22:14 +0200 Subject: [PATCH 6/8] =?UTF-8?q?=20terminado=C2=BF=3F=20falla=20el=20ultimo?= =?UTF-8?q?,=20esta=20bien=20el=20test=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/funcArray.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/funcArray.js b/src/funcArray.js index 40affaa..2b6424c 100644 --- a/src/funcArray.js +++ b/src/funcArray.js @@ -106,7 +106,48 @@ export function howManyTimes(array,buscar){ }); return contador;} } -export function greatestProduct(){} + + //Cual es el producto mayor de cuatro números adyacentes? +export function greatestProduct(array){ + let max= 0; + for (let i =0; i max){ + max = array[i][j]*array[i][j+1]*array[i][j+2]*array[i][j+3]; + }; + } + } + for (let i =0; i max){ + max=array[i][j]*array[i+1][j]*array[i+2][j]*array[i+3][j] + }; + } + } + for (let i =0; i max){ + max = array[i][j]*array[i+1][j-1]*array[i+2][j-2]*array[i+3][j-3] + }; + } + } + let reverse= array.map(x => x.reverse()) + for (let i =0; i max){ + max = reverse[i][j]*reverse[i+1][j-1]*reverse[i+2][j-2]*reverse[i+3][j-3] + }; + } + + } + + return max + } + From aebd6e8786eb5d88ec0fdb4daffae65d200a32a5 Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Tue, 10 May 2022 12:50:04 +0200 Subject: [PATCH 7/8] 51 test done, arreglado el ultimo test --- __tests__/funcArray.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/funcArray.spec.js b/__tests__/funcArray.spec.js index 3c837c6..36f038d 100644 --- a/__tests__/funcArray.spec.js +++ b/__tests__/funcArray.spec.js @@ -297,6 +297,6 @@ test('Return 16 when all the numbers of the arrays are 2', ()=> { [20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54], [1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48] ]; - expect(greatestProduct(matrix)).toBe(51267216); + expect(greatestProduct(matrix)).toBe(70600674); }); }); From 4ca59c6c104f31714741dcbc3fdc313d44546c94 Mon Sep 17 00:00:00 2001 From: Sandra Martos Date: Tue, 10 May 2022 14:54:47 +0200 Subject: [PATCH 8/8] mejorado el ultimo ejercicio --- src/funcArray.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/funcArray.js b/src/funcArray.js index 2b6424c..ee30b5f 100644 --- a/src/funcArray.js +++ b/src/funcArray.js @@ -126,7 +126,8 @@ export function greatestProduct(array){ }; } } - for (let i =0; i max){ @@ -134,16 +135,19 @@ export function greatestProduct(array){ }; } } + } + recorrerDiagonal(array); let reverse= array.map(x => x.reverse()) - for (let i =0; i max){ - max = reverse[i][j]*reverse[i+1][j-1]*reverse[i+2][j-2]*reverse[i+3][j-3] - }; - } + recorrerDiagonal(reverse); + // for (let i =0; i max){ + // max = reverse[i][j]*reverse[i+1][j-1]*reverse[i+2][j-2]*reverse[i+3][j-3] + // }; + // } - } + // } return max }