From 37142256b44b144af56c1331bfdb28d894fb9b4a Mon Sep 17 00:00:00 2001 From: brianschnee Date: Tue, 14 Jun 2022 15:00:28 -0400 Subject: [PATCH] makes keywords inside the keyword array lowercase, for our matches search --- public/js/main.js | 2 +- server.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index a7d3a3d..a6b3949 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -13,7 +13,7 @@ async function getMatches() { const res = await fetch('/api'); const data = await res.json(); // Filters array from the API for resources with keywords containing user value - const matches = data.filter(resource => resource.keywords.some(str => str.includes(keyword))); + const matches = data.filter(resource => resource.keywords.some(str => str.toLowerCase().includes(keyword))); renderMatches(matches); } catch (err) { console.error(err); diff --git a/server.js b/server.js index 4f85cc3..1aa9712 100644 --- a/server.js +++ b/server.js @@ -2,8 +2,6 @@ const express = require('express'); const app = express(); const cors = require('cors'); const { resources } = require("./resources"); -const { response } = require('express'); -const e = require('express'); const PORT = process.env.PORT || 8000; app.set('view engine', 'ejs') @@ -31,7 +29,7 @@ app.get('/api/:keyword', (req, res) => { const keyword = req.params.keyword.toLowerCase(); // filter resources array, return items that match query; tag. - const matches = resources.filter((obj) => obj.keywords.some(str => str.includes(keyword))); + const matches = resources.filter((obj) => obj.keywords.some(str => str.toLowerCase().includes(keyword))); // if matches were found, respond with matches array in JSON format if (matches.length) {