Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Validate PR Metadata
on:
pull_request_target:
types:
- labeled
- unlabeled
- opened
- edited
- reopened

jobs:
validate_pr_metadata:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: CodeYourFuture/actions/validate-pr-metadata@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions Module-Data-Groups-sprint2-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.DS_Store
.vscode
**/.DS_Store
.idea
package-lock.json
19 changes: 19 additions & 0 deletions Module-Data-Groups-sprint2-data/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Predict and explain first...

// This code should log out the houseNumber from the address object
// but it isn't working...
// Fix anything that isn't working
Expand All @@ -13,3 +12,20 @@ const address = {
};

console.log(`My house number is ${address[0]}`);


This code doesnot work because address[0] is calling objects not array.
Instead of using ${address[0]}, we should use $[address.houseNumber].




const address = {
houseNumber: 42,
street: "Imaginary Road",
city: "Manchester",
country: "England",
postcode: "XYZ 123",
};

console.log(`My house number is ${address.houseNumber}`);
33 changes: 33 additions & 0 deletions Module-Data-Groups-sprint2-data/Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Predict and explain first...

// This program attempts to log out all the property values in the object.
// But it isn't working. Explain why first and then fix the problem

const author = {
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 40,
alive: true,
};

for (const value in author){
console.log(value);
}

because we use for...of loop in array instead of objects. To use it in objects, we can change it to for...in loop
In order to print out all the variable and the value , we should use console.log(${key}:${author[key]}).



const author = {
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 40,
alive: true,
};

for (const key in author) {
console.log(`${key}: ${author[key]}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ const recipe = {
console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);


We should not call directly the variable instead we should use recipe.ingredients to call the value insides the label.


const recipe = {
title: "bruschetta",
serves: 2,
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
};

console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe.ingredients}`);
33 changes: 33 additions & 0 deletions Module-Data-Groups-sprint2-data/Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const object = {
a: 1,
b: 2,
};

function contains(object, key) {
if (Array.isArray(object)) {
throw new Error();
}

if (!object) {
return false;
}

if (key in object) {
return true;
} else {
return false;
}
}

module.exports = contains;

/*
Implement a function called contains that checks an object contains a
particular property

E.g. contains({a: 1, b: 2}, 'a') // returns true
as the object contains a key of 'a'

E.g. contains({a: 1, b: 2}, 'c') // returns false
as the object doesn't contains a key of 'c'
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const contains = require("./contains.js");

/*
Implement a function called contains that checks an object contains a
particular property

E.g. contains({a: 1, b: 2}, 'a') // returns true
as the object contains a key of 'a'

E.g. contains({a: 1, b: 2}, 'c') // returns false
as the object doesn't contains a key of 'c'
*/

// Acceptance criteria:

describe("contains function", () => {
test("return true when there is a variable inside", () => {
const object = {
a: 1,
b: 2,
};
const key = "c";
expect(contains(object, key)).toBe(false);
});

test("Given an empty object", () => {
const object = {};
const key = "c";
expect(contains(object, key)).toBe(false);
});

test("Given an object with properties", () => {
const object = {
a: 1,
b: 2,
};
const key = "b";
expect(contains(object, key)).toBe(true);
});

test("Given an object with non-existing properties", () => {
const object = {
a: 1,
b: 2,
};
const key = "c";
expect(contains(object.key)).toBe(false);
});

test("Given invalid parameters like an array", () => {
const object = ["apple", "orange"];
const key = "c";
expect(() => contains(object, key)).toThrow();
});
//if it is array !objects , you should throw errors//
});

// Given a contains function
// When passed an object and a property name
// Then it should return true if the object contains the property, false otherwise

// Given an empty object
// When passed to contains
// Then it should return false

// Given an object with properties
// When passed to contains with an existing property name
// Then it should return true

// Given an object with properties
// When passed to contains with a non-existent property name
// Then it should return false

// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
13 changes: 13 additions & 0 deletions Module-Data-Groups-sprint2-data/Sprint-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function createLookup(pairs) {
if (!Array.isArray(pairs)) {
throw Error;
}
const myLookup = {};

for (let pair of pairs) {
myLookup[pair[0]] = pair[1];
}
return myLookup;
}

module.exports = createLookup;
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
const createLookup = require("./lookup.js");

test.todo("creates a country currency code lookup for multiple codes");

describe("lookup function", () => {
test("creates a country currency code lookup for multiple codes", () => {
const countryCurrentPairs = [
["US", "USD"],
["CA", "CAD"],
];
expect(createLookup(countryCurrentPairs)).toEqual({ US: "USD", CA: "CAD" });
});

test("it show a string and will throw error", () => {
expect(() => {
createLookup("Red");
}).toThrow();
});

test(" it throws empty array , it will return an empty object", () => {
expect(createLookup([])).toEqual({});
});
});
/*

Create a lookup object of key value pairs from an array of code pairs
Expand Down
56 changes: 56 additions & 0 deletions Module-Data-Groups-sprint2-data/Sprint-2/implement/querystring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function parseQueryString(queryString) {
const result = {};

if (queryString.length === 0) {
return result;
}

const keyValuePairs = queryString.split("&");

for (let pair of keyValuePairs) {
const cleanPair = pair.replace(/\+/g, " ");
// Step 3: Change all '+' signs into regular spaces
const firstEqualIndex = cleanPair.indexOf("=");

let key, value;

if (firstEqualIndex === -1) {
key = cleanPair;
value = "";
} else {
key = cleanPair.slice(0, firstEqualIndex);
value = cleanPair.slice(firstEqualIndex + 1);
}

let decodedKey, decodedValue;
try {
// Try to decode normally
decodedKey = decodeURIComponent(key);
} catch (error) {
// If it's a broken code (like "100%"), just use the raw text instead of crashing!
decodedKey = key;
}

try {
decodedValue = decodeURIComponent(value);
} catch (error) {
decodedValue = value;
}

// Step 6: Put them into our boxes (Handling the Stretch Goal too!)
if (result.hasOwnProperty(decodedKey)) {
// If the box already has a secret message, make it a list or add to the list
if (!Array.isArray(result[decodedKey])) {
result[decodedKey] = [result[decodedKey]];
}
result[decodedKey].push(decodedValue);
} else {
// If the box is brand new, just put the message inside
result[decodedKey] = decodedValue;
}
}

return result;
}

module.exports = parseQueryString;
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,45 @@
// Below are some test cases the implementation doesn't handle well.
// Fix the implementation for these tests, and try to think of as many other edge cases as possible - write tests and fix those too.

const parseQueryString = require("./querystring.js")
const parseQueryString = require("./querystring.js");

test("should parse values containing '='", () => {
expect(parseQueryString("equation=a=b-2")).toEqual({
equation: "a=b-2",
});
});

test("should ignore empty key-value pairs", () => {
expect(parseQueryString("key1=value1&&key2=value2&")).toEqual({
key1: "value1",
key2: "value2",
});
expect(parseQueryString("")).toEqual({});
});

test("should accept empty string as key or as value", () => {
expect(parseQueryString("=value")).toEqual({ "": "value" });
expect(parseQueryString("key")).toEqual({ key: "" });
expect(parseQueryString("key=")).toEqual({ key: "" });
expect(parseQueryString("=")).toEqual({ "": "" });
});

test("should decode percent-encoded characters", () => {
expect(parseQueryString("%24half=1%2F2")).toEqual({
$half: "1/2",
});
});
//

test("should replace '+' by ' '", () => {
expect(parseQueryString("full+name=John+Doe")).toEqual({
"full name": "John Doe",
});
});

// Stretch exercise: Handling query strings that contain identical keys
test("should ignore extra or duplicate ampersands", () => {
expect(parseQueryString("key1=value1&key2=value2")).toEqual({
key1: "value1",
key2: "value2",
});
});

// Delete this test if you are not working on this optional case
test("should store values of a key in an array when the key has 2 or more values", () => {
expect(parseQueryString("key=value1&key=value2&key=value3&foo=bar")).toEqual({
key: ["value1", "value2", "value3"],
foo: "bar",
test("should not crash when given malformed percent-encoding", () => {
// If decoding fails, it should just keep the original raw text safely
expect(parseQueryString("discount=100%")).toEqual({
discount: "100%",
});
});
Loading
Loading