GoConqr has a new look! Let us know what you think.

Module 32 of 35 · Text

#32

welligton costa

  

/ *

Escreva uma função que:

- recebe uma série de strings como entrada

- remove todos os espaços no início ou no final das strings

- remove quaisquer barras (/) nas strings

- torna a string toda em minúsculas

* /

 

 

function tidyUpString(strArr) {}

 

/ *

Conclua a função para verificar se a variável `num` atende aos seguintes requisitos:

- é um número

- é mesmo

- é menor ou igual a 100

Dica: use operadores lógicos

* /

 

function validate(num) {}

 

/ *

Escreva uma função que remove um elemento de uma matriz

A função deve:

- NÃO mude a matriz original

- retorna uma nova matriz com o item removido

- remove o item no índice especificado

* /

 

 

function remove(arr, index) {

return; // complete this statement

}

 

/ *

Escreva uma função que:

- pega uma matriz de números como entrada

- retorna uma matriz de strings formatadas como porcentagens (por exemplo, 10 => "10%")

- os números devem ser arredondados para 2 casas decimais

- números maiores de 100 devem ser substituídos por 100

* /

 

 

function formatPercentage(arr) {

}

/* ======= TESTS - DO NOT MODIFY ===== */

function arraysEqual(a, b) {

if (a === b) return true;

if (a == null || b == null) return false;

if (a.length != b.length) return false;

for (let i = 0; i < a.length; ++i) {

if (a[i] !== b[i]) return false;

}

return true;

}

function test(test_name, expr) {

let status;

if (expr) {

status = "PASSED";

} else {

status = "FAILED";

}

console.log(`${test_name}: ${status}`);

}

test(

"tidyUpString function works - case 1",

arraysEqual(tidyUpString(["/Daniel ", "irina ", " Gordon", "ashleigh "]), [

"daniel",

"irina",

"gordon",

"ashleigh"

])

);

test(

"tidyUpString function works - case 2",

arraysEqual(

tidyUpString([" /Sanyia ", " Michael ", "AnTHonY ", " Tim "]),

["sanyia", "michael", "anthony", "tim"]

)

);

test("validate function works - case 1", validate(10) === true);

test("validate function works - case 2", validate(18) === true);

test("validate function works - case 3", validate(17) === false);

test("validate function works - case 4", validate("Ten") === false);

test("validate function works - case 5", validate(108) === false);

test(

"remove function works - case 1",

arraysEqual(remove([10, 293, 292, 176, 29], 3), [10, 293, 292, 29])

);

test(

"remove function works - case 1",

arraysEqual(remove(["a", "b", "c", "d", "e", "f", "g"], 6), [

"a",

"b",

"c",

"d",

"e",

"f"

])

);

test(

"formatPercentage function works - case 1",

arraysEqual(formatPercentage([23, 18, 187.2, 0.372]), [

"23%",

"18%",

"100%",

"0.37%"

])

);

  • © 2020 GitHub, Inc.

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?