-
Notifications
You must be signed in to change notification settings - Fork 61
omar submission #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
omar submission #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,46 @@ | ||
| const {a, b, c} = require('../../src/conditional-flow/numeric-conditions') | ||
| const { a, b, c } = require("../../src/conditional-flow/numeric-conditions"); | ||
|
|
||
| describe("Numeric Conditions isArrayEmpty:", () => { | ||
| it("[] is empty", () => { | ||
| expect(a([])).toEqual(true) | ||
| }) | ||
| expect(a([])).toEqual(true); | ||
| }); | ||
| it("[1] is not empty", () => { | ||
| expect(a([1])).toEqual(false) | ||
| }) | ||
| expect(a([1])).toEqual(false); | ||
| }); | ||
|
|
||
| it("['hello', 'Ed'] is not empty", () => { | ||
| expect(a(['hello', 'Ed'])).toEqual(false) | ||
| }) | ||
| }) | ||
| expect(a(["hello", "Ed"])).toEqual(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Numeric conditions isGreaterThan:", () => { | ||
| it("3 is greater than 2", () => { | ||
| expect(b(3, 2)).toEqual(true) | ||
| }) | ||
| expect(b(3, 2)).toEqual(true); | ||
| }); | ||
|
|
||
| it("0 is not greater than 10", () => { | ||
| expect(b(0, 10)).toEqual(false) | ||
| }) | ||
| expect(b(0, 10)).toEqual(false); | ||
| }); | ||
|
|
||
| it("42 is not greater than 42", () => { | ||
| expect(b(42, 42)).toEqual(false) | ||
| }) | ||
| expect(b(42, 42)).toEqual(false); | ||
| }); | ||
|
|
||
| it("-1 is greater than -3", () => { | ||
| expect(b(-1, -3)).toEqual(true) | ||
| }) | ||
| }) | ||
| expect(b(-1, -3)).toEqual(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Numeric Conditions findLowest:", () => { | ||
| it("1 is lowest in [10, 8, 4, 1, 8]", () => { | ||
| expect(c([10, 8, 4, 1, 8])).toEqual(1) | ||
| }) | ||
| expect(c([10, 8, 4, 1, 8])).toEqual(1); | ||
| }); | ||
|
|
||
| it("-10 is lowest in [0, 0, -10]", () => { | ||
| expect(c([0, 0, -10])).toEqual(-10) | ||
| }) | ||
| expect(c([0, 0, -10])).toEqual(-10); | ||
| }); | ||
|
|
||
| it("100 is lowest in [100,100,100,100]", () => { | ||
| expect(c([100, 100, 100])).toEqual(100) | ||
| }) | ||
| }) | ||
| expect(c([100, 100, 100])).toEqual(100); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| // This function should accept a boolean value and return the string | ||
| // "Well done, you passed!" if the value is true, or "Sorry, try again" | ||
| // if the value is false. | ||
| function getResult (didPass) { | ||
| function getResult(didPass) { | ||
| if (didPass == true) { | ||
| return "Well done, you passed!"; | ||
| } else { | ||
| return "Sorry, try again"; | ||
| } | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| module.exports = { | ||
| a: getResult | ||
| } | ||
| a: getResult, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,17 @@ | ||
| // This function should return true if num is greater | ||
| // than or equal to lower AND less than or equal to upper. | ||
| // Implement this with a single condition. | ||
| function isInRange (num, lower, upper) { | ||
|
|
||
| function isInRange(num, lower, upper) { | ||
| return num >= lower && num <= upper ? true : false; | ||
alsyoufomar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| // This function should return true if the passed string is equal | ||
| // to "Hello" or "Goodbye". Implement this with a single | ||
| // if statement. | ||
| function isHelloOrGoodbye (val1) { | ||
|
|
||
| function isHelloOrGoodbye(val1) { | ||
| return val1 === "Hello" || val1 === "Goodbye" ? true : false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. The ternary operator is not needed. This can be simplified to return val1 === 'Hello' || val1 === 'Goodbye' |
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| // This function should return a string that describes the provided age value. The | ||
|
|
@@ -28,13 +26,23 @@ function isHelloOrGoodbye (val1) { | |
| // 5-12 | Child | ||
| // 13-19 | Teenager | ||
| // 20+ | Adult | ||
| function getAgeDescription (age) { | ||
|
|
||
| function getAgeDescription(age) { | ||
| return age === 0 | ||
| ? "Baby" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be better as an if statement. Nested ternarys are really hard to read and even harder to maintain. |
||
| : age >= 1 && age <= 4 | ||
| ? "Toddler" | ||
| : age >= 5 && age <= 12 | ||
| ? "Child" | ||
| : age >= 13 && age <= 19 | ||
| ? "Teenager" | ||
| : age >= 20 | ||
| ? "Adult" | ||
| : false; | ||
| // TODO: write code in this function body to pass the tests | ||
| } | ||
|
|
||
| module.exports = { | ||
| a: isInRange, | ||
| b: isHelloOrGoodbye, | ||
| c: getAgeDescription | ||
| } | ||
| c: getAgeDescription, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,36 @@ | ||
| // TODO: Implement the functions below to make the tests pass | ||
|
|
||
| // This function should return true if there are no elements in the array, false otherwise | ||
| function isArrayEmpty (array) { | ||
|
|
||
| function isArrayEmpty(array) { | ||
| return array.length == 0 ? true : false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified to: return array.length == 0 |
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| // This function should return true if num1 is greater than num2, false otherwise | ||
| function isGreaterThan (num1, num2) { | ||
|
|
||
| function isGreaterThan(num1, num2) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (num1 > num2) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if statement is not needed here as return num1 > num2 |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // This function should return the lowest number in the passed array | ||
| function findLowest (nums) { | ||
|
|
||
| function findLowest(nums) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| let i = 0; | ||
| var lowest = nums[i]; | ||
| for (i = 0; i < nums.length; i++) { | ||
| if (lowest > nums[i]) { | ||
| lowest = nums[i]; | ||
| } | ||
| } | ||
| return lowest; | ||
| } | ||
|
|
||
| module.exports = { | ||
| a: isArrayEmpty, | ||
| b: isGreaterThan, | ||
| c: findLowest | ||
| } | ||
| c: findLowest, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,73 @@ | ||
| // This function should return true if the passed string is equal to "Hello" | ||
| function isHello (val1) { | ||
|
|
||
| function isHello(val1) { | ||
| if (val1 === "Hello") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
return val1 === "Hello" |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| // This function should return true if the passed string is not equal to "Hello" | ||
| function isNotHello (val1) { | ||
|
|
||
| function isNotHello(val1) { | ||
| if (val1 !== "Hello") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, the if statement here isn't required as |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| // This function should return true if the string val1 is is longer | ||
| // than string val2 | ||
| function isLongerThan (val1, val2) { | ||
|
|
||
| function isLongerThan(val1, val2) { | ||
| if (val1.length > val2.length) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if statement is not needed :) |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| // This function should return true if the string passed in the function's first | ||
| // argument has an odd number of vowels | ||
|
|
||
| function hasOddNumberVowels (val1) { | ||
| function hasOddNumberVowels(val1) { | ||
| let count = 0; | ||
| let smallVal = val1.toLowerCase(); | ||
| for (i = 0; i < smallVal.length; i++) { | ||
| if ( | ||
| smallVal[i] == "a" || | ||
| smallVal[i] == "i" || | ||
| smallVal[i] == "e" || | ||
| smallVal[i] == "o" || | ||
| smallVal[i] == "u" | ||
| ) { | ||
| count++; | ||
| } | ||
| } | ||
| if (count % 2 === 1) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if statement isn't required as |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| } | ||
|
|
||
| // this function should return the middle character of a string if it has an odd number | ||
| // of characters. If there are an even number of characters the function should return | ||
| // the middle two letters | ||
|
|
||
| function getMiddleLetter (val1) { | ||
| function getMiddleLetter(val1) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (val1.length % 2 === 1) { | ||
| let oddIndex = Math.floor(val1.length / 2); | ||
| return val1[oddIndex]; | ||
| } else { | ||
| let evenIndex = val1.length / 2; | ||
| return val1[evenIndex - 1] + val1[evenIndex]; | ||
| } | ||
| } | ||
|
|
||
| // This function should return the name of the season for the provided | ||
|
|
@@ -47,9 +79,29 @@ function getMiddleLetter (val1) { | |
| // Summer - June to August | ||
| // Autumn - September to November | ||
| // Winter - December to February | ||
| function seasonForMonth (monthName) { | ||
|
|
||
| function seasonForMonth(monthName) { | ||
| // TODO: write code in this function body to pass the tests | ||
| let LowerCaseMonthName = monthName.toLowerCase(); | ||
| switch (LowerCaseMonthName) { | ||
| case "march": | ||
| case "april": | ||
| case "may": | ||
| return "Spring"; | ||
| case "june": | ||
| case "july": | ||
| case "august": | ||
| return "Summer"; | ||
| case "september": | ||
| case "october": | ||
| case "november": | ||
| return "Autumn"; | ||
| case "december": | ||
| case "january": | ||
| case "february": | ||
| return "Winter"; | ||
| default: | ||
| return ""; | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
|
|
@@ -58,5 +110,5 @@ module.exports = { | |
| c: isLongerThan, | ||
| d: hasOddNumberVowels, | ||
| e: getMiddleLetter, | ||
| f: seasonForMonth | ||
| } | ||
| f: seasonForMonth, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,24 @@ | ||
| // do not edit this section | ||
| const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] | ||
| const cities = ["London", "Shanghai", "New York", "Delhi", "Kuala Lumpur"]; | ||
|
|
||
| // TODO: write code to pass the tests | ||
|
|
||
| // Set names equal to an array containing 'Bob', 'Jane', 'Joanna' in that order | ||
| const names = null | ||
| const names = ["Bob", "Jane", "Joanna"]; | ||
|
|
||
| // Set fourthCity to the 4th element in the cities array | ||
| const fourthCity = '' | ||
| const fourthCity = "Delhi"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect. You need to get the |
||
|
|
||
| // Set firstCity to the 1st element in the cities array | ||
| const firstCity = '' | ||
| const firstCity = "London"; | ||
|
|
||
| // Set lengthOfCitiesArray to the length of the cities array | ||
| const lengthOfCitiesArray = NaN | ||
| const lengthOfCitiesArray = 5; | ||
|
|
||
| // Do not edit this exported object | ||
| module.exports = { | ||
| a: names, | ||
| b: fourthCity, | ||
| c: firstCity, | ||
| d: lengthOfCitiesArray | ||
| } | ||
| d: lengthOfCitiesArray, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't really need the else here, you could just have the
This is because
didPasswill either be true or false. So in the case it is true, your function will stop when you return Well done. In the case it is false, it will skip the if statement and go onto the next line; in the code I showed above, it'll return Sorry.Hope that makes sense!