-
Notifications
You must be signed in to change notification settings - Fork 61
My pull request #14
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?
My pull request #14
Changes from all commits
bb18909
39de6c7
4c80dbc
5a2d39a
4e6eef0
54cecd6
60d646e
7e3da10
8a83d28
6826ab2
255cc08
3059489
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,21 +1,21 @@ | ||
| const {a, b} = require('../../src/functions/creating-functions-multiple-args') | ||
| const { a, b } = require('../../src/functions/creating-functions-multiple-args') | ||
|
|
||
| describe("Creating Functions Multiple Args:", () => { | ||
|
|
||
| it("First function returns range 1 to 3", () => { | ||
| expect(a(1, 3)).toEqual([1,2,3]) | ||
| }) | ||
| it("First function returns range 1 to 3", () => { | ||
| expect(a(1, 3)).toEqual([1, 2, 3]) | ||
| }) | ||
|
|
||
| it("First function returns range -1 to 1", () => { | ||
| expect(a(-1, 1)).toEqual([-1,0,1]) | ||
| }) | ||
| it("First function returns range -1 to 1", () => { | ||
| expect(a(-1, 1)).toEqual([-1, 0, 1]) | ||
| }) | ||
|
|
||
| it("Second function returns oh no with single exclamation", () => { | ||
| expect(b("oh no",1)).toEqual("OH NO!") | ||
| }) | ||
| it("Second function returns oh no with single exclamation", () => { | ||
| expect(b("oh no", 1)).toEqual("OH NO!") | ||
| }) | ||
|
|
||
| it("Second function returns watch out with 6 exclamations", () => { | ||
| expect(b("watch out",6)).toEqual("WATCH OUT!!!!!!") | ||
| }) | ||
| it("Second function returns watch out with 6 exclamations", () => { | ||
| expect(b("watch out", 6)).toEqual("WATCH OUT!!!!!!") | ||
| }) | ||
|
|
||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| // 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) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| // TODO: write code in this function body to pass the tests | ||
| return didPass === true ? 'Well done, you passed!' : 'Sorry, try again' | ||
|
|
||
| } | ||
|
|
||
| module.exports = { | ||
| a: getResult | ||
| } | ||
| a: getResult | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,26 @@ | ||
| // 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) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (num >= lower && num <= upper) { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // 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) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| function isHelloOrGoodbye(val1) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| if (val1 === 'Hello' || val1 === 'Goodbye') { | ||
|
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 here just return the boolean |
||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // This function should return a string that describes the provided age value. The | ||
|
|
@@ -28,13 +35,25 @@ function isHelloOrGoodbye (val1) { | |
| // 5-12 | Child | ||
| // 13-19 | Teenager | ||
| // 20+ | Adult | ||
| function getAgeDescription (age) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| function getAgeDescription(age) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| let input = age | ||
| if (input === 0) { | ||
| return 'Baby' | ||
| } else if (input >= 1 && input <= 4) { | ||
| return 'Toddler' | ||
| } else if (input >= 5 && input <= 12) { | ||
| return 'Child' | ||
| } else if (input >= 13 && input <= 19) { | ||
| return 'Teenager' | ||
| } else if (input >= 20) { | ||
| return 'Adult' | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| a: isInRange, | ||
| b: isHelloOrGoodbye, | ||
| c: getAgeDescription | ||
| } | ||
| a: isInRange, | ||
| b: isHelloOrGoodbye, | ||
| c: getAgeDescription | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,46 @@ | ||
| // 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) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| function isArrayEmpty(array) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| if (array.length === 0) { | ||
|
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 here just return the boolean |
||
| return true | ||
| } else { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // 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 | ||
| // TODO: write code in this function body to pass the tests | ||
| if (num1 > num2) { | ||
|
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 here just return the boolean |
||
| return true | ||
| } else { | ||
| return false | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // This function should return the lowest number in the passed array | ||
| function findLowest (nums) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| function findLowest(nums) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| //return Math.min(...nums) | ||
| let lowNum = nums[0] | ||
| for (let i = 1; i < nums.length; i++) { | ||
| if (lowNum > nums[i]) { | ||
| lowNum = nums[i] | ||
| } | ||
| } | ||
| return lowNum | ||
| } | ||
|
|
||
|
|
||
| module.exports = { | ||
| a: isArrayEmpty, | ||
| b: isGreaterThan, | ||
| c: findLowest | ||
| } | ||
| a: isArrayEmpty, | ||
| b: isGreaterThan, | ||
| c: findLowest | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,82 @@ | ||
| // This function should return true if the passed string is equal to "Hello" | ||
| function isHello (val1) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| function isHello(val1) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| if (val1 === 'Hello') { | ||
|
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 here just return the boolean |
||
| return true | ||
| } else { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // This function should return true if the passed string is not equal to "Hello" | ||
| function isNotHello (val1) { | ||
| function isNotHello(val1) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| // TODO: write code in this function body to pass the tests | ||
| if (val1 !== 'Hello') { | ||
| return true | ||
|
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 here just return the boolean |
||
| } else { | ||
| return false | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // This function should return true if the string val1 is is longer | ||
| // than string val2 | ||
| function isLongerThan (val1, val2) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| function isLongerThan(val1, val2) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| if (val1.length > val2.length) { return true } else { | ||
|
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 here just return the boolean |
||
| return false | ||
| } | ||
| } | ||
|
|
||
| // 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) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] | ||
|
|
||
| let counts = 0 | ||
| for (let i = 0; i < val1.length; i++) { | ||
| if (vowels.includes(val1[i])) { | ||
| counts++ | ||
| } | ||
| } | ||
| if (counts % 2 !== 0) { | ||
|
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 here just return the boolean (the condition) |
||
| return true | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| } else { | ||
| return false | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| // 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) { | ||
| // TODO: write code in this function body to pass the tests | ||
| function getMiddleLetter(val1) { | ||
| // TODO: write code in this function body to pass the tests | ||
| let position = []; | ||
| let length = ''; | ||
|
|
||
| if (val1.length % 2 == 0) { | ||
| position = val1.length / 2; | ||
| length = 0; | ||
| return val1[position - 1] + val1[position] | ||
| } else { | ||
| position = val1.length / 2 - 1; | ||
| length = 2; | ||
| return val1[Math.ceil(position)] | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| // This function should return the name of the season for the provided | ||
| // month name. For example, "January" should return "Winter". If the provided | ||
| // value is not a valid month, an empty string ("") should be returned. Use | ||
|
|
@@ -47,16 +86,41 @@ function getMiddleLetter (val1) { | |
| // Summer - June to August | ||
| // Autumn - September to November | ||
| // Winter - December to February | ||
| function seasonForMonth (monthName) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| function seasonForMonth(monthName) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| let seasons = '' | ||
|
|
||
| switch (monthName) { | ||
| case 'March': | ||
| case 'April': | ||
| case 'May': | ||
| seasons = 'Spring' | ||
| break; | ||
| case 'June': | ||
| case 'July': | ||
| case 'August': | ||
| seasons = 'Summer' | ||
| break; | ||
| case 'September': | ||
| case 'October': | ||
| case 'November': | ||
| seasons = 'Autumn' | ||
| break; | ||
| case 'December': | ||
| case 'January': | ||
| case 'February': | ||
| seasons = 'Winter' | ||
| break; | ||
| } | ||
| return seasons | ||
| } | ||
|
|
||
| module.exports = { | ||
| a: isHello, | ||
| b: isNotHello, | ||
| c: isLongerThan, | ||
| d: hasOddNumberVowels, | ||
| e: getMiddleLetter, | ||
| f: seasonForMonth | ||
| } | ||
| a: isHello, | ||
| b: isNotHello, | ||
| c: isLongerThan, | ||
| d: hasOddNumberVowels, | ||
| e: getMiddleLetter, | ||
| f: seasonForMonth | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,21 +4,21 @@ 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' | ||
|
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. You have hard coded this, but should be accessing the 3rd element in the array: cities[3] |
||
|
|
||
| // Set firstCity to the 1st element in the cities array | ||
| const firstCity = '' | ||
| const firstCity = 'London' | ||
|
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. again should not be hard coded |
||
|
|
||
| // 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 | ||
| } | ||
| a: names, | ||
| b: fourthCity, | ||
| c: firstCity, | ||
| 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.
an if statement is not needed here you can just return the boolean, like this: