From d2f254dd6cca6bcb856263771a3995fc534d0e51 Mon Sep 17 00:00:00 2001 From: Andresa Date: Wed, 2 Nov 2022 14:50:03 -0300 Subject: [PATCH] fix (sum) ajuste --- 01-greeting/index.js | 2 +- 02-triangleArea/index.js | 11 ++--------- 03-maxValue/index.js | 15 ++++++++------- 04-fibonacci/index.js | 31 +++++++++++-------------------- 05-isPrime/index.js | 26 +++++++++----------------- 06-sum/index.js | 13 +++++-------- 07-sumEven/index.js | 19 ++++++++----------- 09-mostRepeatedChar/index.js | 30 +++++++++++++----------------- 8 files changed, 57 insertions(+), 90 deletions(-) diff --git a/01-greeting/index.js b/01-greeting/index.js index 185f985..7928ce4 100644 --- a/01-greeting/index.js +++ b/01-greeting/index.js @@ -1,7 +1,7 @@ export function greet(name) { // function greet(name) { - return'Hello ${name};' + return `Hello ${name}` } diff --git a/02-triangleArea/index.js b/02-triangleArea/index.js index 5681e7a..b14ec43 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,10 +1,3 @@ -export function triangleArea(base, height) { - - constbase, altura, area; - escreva;('informe a base do triangulo:') - leia;(altura);area:(base, altura)/2 - escreva (areadoTriangulosera,area5) - - - // your code here +export function triangleArea(base, height) { + return base * height / 2 } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index 330db48..f07346f 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,9 +1,10 @@ export function maxValue(values) { - - - var arr = [1, 2, 3]; var max = arr. reduce(function(a, b) { return Math. max(a, b); }, -Infinity); + var arr = values; -function getMaxOfArray(numArray) { return Math. max. apply(null, numArray); } -var arr = [50, 10,30, 10]; var max = Math. max(... arr); - -} \ No newline at end of file + if (arr.length == 0) return 0; + var max1 = arr.reduce(function (a, b) { + return Math.max(a, b); + }, -Infinity); + + return max1; +} diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index f69d647..0c8a62d 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,22 +1,13 @@ export function fibonacci(value) { - - - function fibonacci(){ - var termo = parseInt(document.getElementById('numero').value); - var resposta = document.getElementById('resposta'); - var penultimo=0, ultimo=1; - var numero; - - if(termo<=2) - numero = termo-1; - else - for(var count=3 ; count<=termo ; count++){ - numero = ultimo + penultimo; - penultimo = ultimo; - ultimo = numero; - } - - resposta.innerHTML=numero; + var i; + var fib = [0, 1]; + let numero = undefined; + for (i = 2; i <= value; i++) { + fib[i] = fib[i - 2] + fib[i - 1]; + numero = fib[i]; } - -} \ No newline at end of file + + if (numero !== undefined) return numero; + + return value; +} diff --git a/05-isPrime/index.js b/05-isPrime/index.js index f91e6d5..0cd4f9c 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,18 +1,10 @@ export function isPrime(value) { - - function primo(){ - var numero = parseInt(document.getElementById('num').value); - var resposta = document.getElementById('resposta'); - var divisores=0; - - for(var count=1 ; count<=numero ; count++) - if(numero % count == 0) - divisores++; - - if(divisores==2) - resposta.innerHTML='É primo'; - else - resposta.innerHTML='Não é primo'; - } - -} \ No newline at end of file + var numero = parseInt(value); + var divisores = 0; + + for (var count = 1; count <= numero; count++) + if (numero % count == 0) divisores++; + + if (divisores == 2) return true; + else return false; +} diff --git a/06-sum/index.js b/06-sum/index.js index c5136b2..502d4ec 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,12 +1,9 @@ export function sum(values) { - var numbers = [15,40,55]; + let sum = 0; -var sum = 0; + values.forEach((element) => { + sum += element; + }); -for(var i =0;i { + if (item % 2 == 0) return item; + }); - let numerosPares = []; - for (let i = 0; i < n; i++) { - if (i % 2 == 0) { - numerosPares.push(i) - } - } - return numerosPares; + numerosPares.forEach((num) => { + if (num !== undefined) soma += num; + }); + return soma; } -retornaNNumerosPares(1, 40) - -} \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index d19e2af..f526d92 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,19 +1,15 @@ export function mostUsedChar(text) { - - function mostUsedChar(text) { - - - nomes = ["fdgdfgf","Lorem ipsum","adsassdasd","testeeeee"]; - - function retornarLetramaisRepetida(item, indice) { - nomes[indice] = nomes[indice].toUpperCase(); - } - - nomes.forEach(retornarLetramaisRepetida); - console.log(nomes); - - return "e" - } + var getMax = function (str) { + var max = 0, + maxChar = ""; + str.split("").forEach(function (char) { + if (str.split(char).length > max) { + max = str.split(char).length; + maxChar = char; + } + }); + return maxChar; + }; - - } + return getMax(text); +}