From a11725d6eca27c68cc706d97238e978bd4dcb3d6 Mon Sep 17 00:00:00 2001 From: Divlo Date: Wed, 13 May 2020 00:08:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Small=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/convertRomanArabicNumbers.js | 24 +++++++++---------- api/assets/functions/main/rightPrice.js | 7 +++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/api/assets/functions/main/convertRomanArabicNumbers.js b/api/assets/functions/main/convertRomanArabicNumbers.js index 8c578fb..ef020a9 100644 --- a/api/assets/functions/main/convertRomanArabicNumbers.js +++ b/api/assets/functions/main/convertRomanArabicNumbers.js @@ -21,8 +21,8 @@ const correspondancesRomainArabe = [ /** * @description Convertis un nombre arabe en nombre romain. - * @param {Number} nombre - Le nombre arabe à convertir - * @returns {String} + * @param {number} nombre - Le nombre arabe à convertir + * @returns {string} * @examples convertArabicToRoman(24) → 'XXIV' */ function convertArabicToRoman(nombre) { @@ -45,21 +45,21 @@ function convertArabicToRoman(nombre) { /** * @description Convertis un nombre romain en nombre arabe. - * @param {String} str - Le nombre romain à convertir - * @returns {Number} - * @examples convertRomanToArabic('XXIV') → 24 + * @param {string} string - Le nombre romain à convertir + * @return {number} + * @example convertRomanToArabic('XXIV') → 24 */ -function convertRomanToArabic(str) { +function convertRomanToArabic(string) { let result = 0; - for (let i = 0; i < correspondancesRomainArabe.length; i++) { - while (str.indexOf(correspondancesRomainArabe[i][1]) === 0) { + correspondancesRomainArabe.forEach((correspondance) => { + while (string.indexOf(correspondance[1]) === 0) { // Ajout de la valeur décimale au résultat - result += correspondancesRomainArabe[i][0]; + result += correspondance[0]; // Supprimer la lettre romaine correspondante du début - str = str.replace(correspondancesRomainArabe[i][1],''); + string = string.replace(correspondance[1], ''); } - } - if (str != '') { + }); + if (string != '') { result = 0; } return result; diff --git a/api/assets/functions/main/rightPrice.js b/api/assets/functions/main/rightPrice.js index ac557ae..6642cdc 100644 --- a/api/assets/functions/main/rightPrice.js +++ b/api/assets/functions/main/rightPrice.js @@ -16,7 +16,8 @@ function getRandomArrayElement(array) { return array[randomNumber(0, array.length - 1)]; } -async function getAmazonProductList(url) { +async function getAmazonProductList(subject) { + const url = `https://www.amazon.fr/s?k=${subject}`; const Nightmare = require('nightmare')(); return await Nightmare.goto(url) .wait('.s-result-item') @@ -33,7 +34,7 @@ async function getAmazonProductList(url) { image: productImage["src"], price: Number(originalPrice.replace(",", ".").replace(" ", "")) }); - } catch (error) { + } catch (_error) { continue; } } @@ -44,7 +45,7 @@ async function getAmazonProductList(url) { module.exports = rightPriceOutput = async ({ res }, _argsObject) => { const subject = getRandomArrayElement(subjectList); - const productsList = await getAmazonProductList(`https://www.amazon.fr/s?k=${subject}`); + const productsList = await getAmazonProductList(subject); const randomProduct = getRandomArrayElement(productsList); return res.status(200).json({ subject, ...randomProduct }); } \ No newline at end of file