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

Module 30 of 35 · Text

#30

welligton costa

/ **

* Encontrar uma estação de rádio, e uma boa, pode ser difícil manualmente.

* Vamos usar algum código para nos ajudar a construir um programa que nos ajuda a digitalizar

* as ondas de rádio para uma boa música.

* /

/ **

* Primeiro, vamos criar uma função que cria uma lista de todas as frequências.

* Chame esta função `getAllFrequencies`.

*

* Esta função deve:

* - Crie uma matriz começando em 87 e terminando em 108

* - Deve retornar esta matriz para usar em outras funções

* /

// `getAllFrequencies` vai aqui

/ **

* A seguir, vamos escrever uma função que nos forneça apenas as frequências das estações de rádio.

* Chame esta função `getStations`.

*

* Esta função deve:

* - Obtenha as frequências disponíveis em `getAllFrequencies`

* - Há uma função auxiliar chamada isRadioFrequency que recebe um número inteiro como argumento e retorna um booleano.

* - Retorna apenas as frequências que são estações de rádio.

* /

// `getStations` vai aqui

/ * ======= TESTES - NÃO MODIFICAR ======= * /

 

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

function getAvailableStations() {

// Using `stations` as a property as defining it as a global variable wouldn't

// always make it initialized before the function is called

if (!getAvailableStations.stations) {

const stationCount = 4;

getAvailableStations.stations = new Array(stationCount)

.fill(undefined)

.map(function() {

return Math.floor(Math.random() * (108 - 87 + 1) + 87);

})

.sort(function(frequencyA, frequencyB) {

return frequencyA - frequencyB;

});

}

return getAvailableStations.stations;

}

function isRadioStation(frequency) {

return getAvailableStations().includes(frequency);

}

const assert = require("assert");

function test(testName, fn) {

try {

fn();

console.log(`\n ${testName}: PASS`);

} catch (error) {

console.log(

`\n ${testName}: FAIL (see details below)\n\n${error.message}`

);

}

}

test("getAllFrequencies() returns all frequencies between 87 and 108", function() {

const frequencies = getAllFrequencies();

assert.deepStrictEqual(frequencies, [

87,

88,

89,

90,

91,

92,

93,

94,

95,

96,

97,

98,

99,

100,

101,

102,

103,

104,

105,

106,

107,

108

]);

});

test("getStations() returns all the available stations", () => {

const stations = getStations();

assert.deepStrictEqual(stations, getAvailableStations());

});

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?