-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
Osman Elsahib- TDD #68
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
module.exports = function(numbers) {}; | ||
module.exports = function(numbers) { | ||
return numbers.map((number)=> number +1) | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
var getWordLengths = function(someWords) {}; | ||
var getWordLengths = function (someWords) { | ||
return someWords.map(word => word.length) | ||
}; | ||
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 👍 |
||
|
||
module.exports = getWordLengths; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
function addNumbers(numbers) {} | ||
function addNumbers(numbers) { | ||
return numbers.reduce(function (a, b) { | ||
return a + b; | ||
}, 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. Perfect |
||
|
||
module.exports = addNumbers; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
function findNeedle(words) {} | ||
function findNeedle(words) { | ||
let result; | ||
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. if you look at the test, you have two arguments passed, expecting two parameters. |
||
const lookForWords = ["needle", "plant"] | ||
words.forEach((element, index) => { | ||
lookForWords.includes(element) ? result = index : "Not found" | ||
}); | ||
return result | ||
} | ||
|
||
module.exports = findNeedle; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,14 @@ | |
// calculate and return the factorial of int | ||
// note: factorial of 0 is 1 | ||
|
||
function factorial(int) {} | ||
function factorial(int) { | ||
// let result = 1, i = int; | ||
if (int === 0 || int === 1) | ||
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. while int is not reserved anymore in JS 5, it is reserved word in previous versions afaik 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. Also this will save you the trouble of the first conditions, as you can initialize it with 1 |
||
return 1; | ||
for (var i = int - 1; i >= 1; i--) { | ||
int *= i; | ||
} | ||
return int; | ||
} | ||
|
||
module.exports = factorial; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function removeMiddle(array) { | ||
if (array.length >= 3) { | ||
let index = (array.length - 1) / 2 | ||
return array.splice(index, 1) | ||
} else { return "Can't work with such short array" } | ||
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. I like the creativity, but why can't work with short arrays |
||
} | ||
module.exports = removeMiddle; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function secondLargest(array) { | ||
let actualMax = Math.max(...array) | ||
let maxIndex = array.indexOf(actualMax) | ||
array.splice(maxIndex, 1) | ||
return Math.max(...array) | ||
} | ||
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. nice work, and works fine |
||
|
||
module.exports = secondLargest; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
// the input is an array of numbers and strings | ||
// return the average of all the numbers | ||
// be sure to exclude the strings | ||
function getAverage(array) { | ||
let numArray = []; | ||
array.forEach(element => { | ||
if (typeof element == "number") { | ||
numArray.push(element) | ||
} | ||
}); | ||
let sum = numArray.reduce(function (a, b) { | ||
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. Also nicely done |
||
return a + b; | ||
}, 0); | ||
return sum / numArray.length | ||
|
||
} | ||
module.exports = getAverage; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function carSales(array) { | ||
let result = {}, ford = 0, honda = 0, rover = 0, toyota = 0; | ||
array.forEach(element => { | ||
if (element.make === "Ford") { | ||
ford = ford + element.price | ||
} else if (element.make === "Honda") { | ||
honda = honda + element.price | ||
} else if (element.make === "Land Rover") { | ||
rover = rover + element.price | ||
debugger | ||
} else { | ||
toyota = toyota + element.price | ||
} | ||
|
||
}); | ||
result.Ford = ford | ||
result.Honda = honda | ||
result["Land Rover"] = rover | ||
result.Toyota = toyota | ||
|
||
return result | ||
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. Really good work |
||
|
||
} | ||
module.exports = carSales; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function paintCars(array, color) { | ||
// I didn't understand what is required to be done so I hardcoded the index | ||
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 a tricky one 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. remember it should not change the original object colour |
||
newarray = [...array] | ||
newarray[0] = { ...newarray[0], colour: color } | ||
return newarray | ||
} | ||
module.exports = paintCars; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function cities(array, func) { | ||
return array.map(item => func(item)) | ||
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. correct |
||
} | ||
module.exports = cities; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
function greetPeople(people) { | ||
var greeting = "Hello "; | ||
|
||
people.forEach(function(person) { | ||
greeting = greeting + person; | ||
var myarray = [] | ||
people.forEach(function (person) { | ||
myarray.push(greeting + person); | ||
}); | ||
|
||
return greeting; | ||
return myarray; | ||
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. nice work, while forEach is pushing to another array (not quite its role) |
||
} | ||
|
||
module.exports = greetPeople; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
test("print list of names prefixed with Hello", function() { | ||
const greetPeople = require("./greet-people.js") | ||
|
||
test("print list of names prefixed with Hello", function () { | ||
// Arrange | ||
const mentors = ['Irina', 'Ashleigh', 'Etza']; | ||
const expected = ['Hello Irina', 'Hello Ashleigh', 'Hello Etza']; | ||
// Act | ||
const result = greetPeople(mentors) | ||
|
||
// Assert | ||
expect(result).toEqual(expected) | ||
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. nice work |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,17 @@ function removeVowels(word) { | |
|
||
var result = []; | ||
|
||
characters.forEach(function(character) { | ||
characters.forEach(function (character) { | ||
if ( | ||
character === "a" || | ||
character === "o" || | ||
character === "i" || | ||
character === "e" || | ||
character === "u" | ||
character.toLowerCase() === "a" || | ||
character.toLowerCase() === "o" || | ||
character.toLowerCase() === "i" || | ||
character.toLowerCase() === "e" || | ||
character.toLowerCase() === "u" | ||
) { | ||
result.push(character); | ||
result.push(""); | ||
} else { | ||
result.push("_"); | ||
result.push(character); | ||
} | ||
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 idea for those tests, is to add more tests to make your functions work better. So try to do that and we can review them later on |
||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
test("remove vowels from word", function() { | ||
const removeVowels = require("./remove-vowels.js") | ||
|
||
test("remove vowels from word", function () { | ||
// Arrange | ||
const expected = "sml" | ||
// Act | ||
const result = removeVowels('samuel'); | ||
// Assert | ||
expect(result).toEqual(expected) | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
var largerThanTen = require("./numbersGreaterThan10"); | ||
|
||
test("Get numbers greater than 10", function() {}); | ||
test("Get numbers greater than 10", function () { | ||
const input = [4, 10, 32, 9, 21], | ||
expected = [32, 21], | ||
result = largerThanTen(input) | ||
|
||
expect(result).toEqual(expected) | ||
}); | ||
|
||
|
||
// input: [4, 10, 32, 9, 21]; | ||
// expected output: [32, 21]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
const getEvenNumbers = require("./get-even-numbers") | ||
|
||
test("the even number", function () { | ||
const input = [22, 13, 73, 82, 4], | ||
expected = [22, 82, 4], | ||
result = getEvenNumbers(input) | ||
expect(result).toEqual(expected) | ||
}) | ||
|
||
// example | ||
// input: [22, 13, 73, 82, 4]; | ||
// expected: [22, 82, 4]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
const getRepos = require("./async-1"); | ||
|
||
test("gets a list of repositories names", function() { | ||
test("gets a list of repositories names", function () { | ||
// arrange | ||
var url = "https://api.github.com/users/kabaros/repos"; | ||
// act | ||
return getRepos(url).then(function(result) { | ||
return getRepos(url).then(function (result) { | ||
// assert | ||
expect(result).toContain("js-exercises"); | ||
expect(result).toContain("dom-ajax-repo"); | ||
expect(result).toContain("master-reference"); | ||
expect(result).toContain("sword"); | ||
}); | ||
}); |
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.
Nice one