Skip to content
Open
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions spec/functions/creating-functions-multiple-args.spec.js
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!!!!!!")
})

})
})
9 changes: 5 additions & 4 deletions src/conditional-flow/boolean-conditions.js
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
}
43 changes: 31 additions & 12 deletions src/conditional-flow/multiple-conditions.js
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) {

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:

return 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') {

Choose a reason for hiding this comment

The 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
Expand All @@ -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
}
46 changes: 32 additions & 14 deletions src/conditional-flow/numeric-conditions.js
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) {

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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
}
110 changes: 87 additions & 23 deletions src/conditional-flow/string-conditions.js
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') {

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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 {

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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
Expand All @@ -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
}
18 changes: 9 additions & 9 deletions src/data-types/arrays/accessing-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Choose a reason for hiding this comment

The 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'

Choose a reason for hiding this comment

The 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
}
Loading