From 1b64efca68472ffdd62dd0eaa4b74591dd8c145b Mon Sep 17 00:00:00 2001 From: Lewis Date: Mon, 13 Dec 2021 20:11:19 +0000 Subject: [PATCH] Prototype for protecting from copying and pasting --- spec/data-types/arrays/accessing-elements.spec.js | 4 ++-- src/_support/location.js | 8 ++++++++ src/data-types/arrays/accessing-elements.js | 9 ++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/_support/location.js diff --git a/spec/data-types/arrays/accessing-elements.spec.js b/spec/data-types/arrays/accessing-elements.spec.js index 16fa6fde..4de2a066 100644 --- a/spec/data-types/arrays/accessing-elements.spec.js +++ b/spec/data-types/arrays/accessing-elements.spec.js @@ -6,11 +6,11 @@ describe("Arrays accessing:", () => { }) it("fourthCity is Delhi", () => { - expect(answers.b).toEqual("Delhi") + expect(answers.b).toEqual(answers._c.find(city => city.location === "Delhi")) }) it("firstCity is London", () => { - expect(answers.c).toEqual("London") + expect(answers.c).toEqual(answers._c.find(city => city.location === "London")) }) it("lengthOfCitiesArray is 5", () => { diff --git a/src/_support/location.js b/src/_support/location.js new file mode 100644 index 00000000..6f6e3c24 --- /dev/null +++ b/src/_support/location.js @@ -0,0 +1,8 @@ +class Location { + constructor(location) { + this.location = location; + this.randNumber = Math.floor(Math.random() * 1000); + } +} + +module.exports = Location \ No newline at end of file diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..3b224363 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -1,5 +1,7 @@ +const Location = require('../../_support/location') + // do not edit this section -const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] +const cities = [new Location('London'), new Location('Shanghai'), new Location('New York'), new Location('Delhi'), new Location('Kuala Lumpur')] // TODO: write code to pass the tests @@ -7,16 +9,17 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] const names = null // Set fourthCity to the 4th element in the cities array -const fourthCity = '' +const fourthCity = cities[3] // Set firstCity to the 1st element in the cities array -const firstCity = '' +const firstCity = new Location('London') // Set lengthOfCitiesArray to the length of the cities array const lengthOfCitiesArray = NaN // Do not edit this exported object module.exports = { + _c: cities, a: names, b: fourthCity, c: firstCity,