Grammar cleanups, trailing semicolon for function expressions
This commit is contained in:
parent
276b60a3c3
commit
ac4d2a94e5
|
@ -1,6 +1,6 @@
|
|||
# Exercise XX - caesar cipher
|
||||
# Exercise XX - Caesar cipher
|
||||
|
||||
Implement the legendary caesar cipher:
|
||||
Implement the legendary Caesar cipher:
|
||||
|
||||
> In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.
|
||||
|
||||
|
@ -31,5 +31,3 @@ negative numbers should work as well:
|
|||
```javascript
|
||||
caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!'
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
const add = function(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
};
|
||||
|
||||
const subtract = function(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
};
|
||||
|
||||
const sum = function(array) {
|
||||
return array.reduce((total, current) => total + current, 0);
|
||||
}
|
||||
};
|
||||
|
||||
const multiply = function(array) {
|
||||
return array.length
|
||||
? array.reduce((accumulator, nextItem) => accumulator * nextItem)
|
||||
: 0;
|
||||
}
|
||||
};
|
||||
|
||||
const power = function(a, b) {
|
||||
return Math.pow(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
const factorial = function(n) {
|
||||
if (n == 0) return 1;
|
||||
if (n === 0) return 1;
|
||||
let product = 1;
|
||||
for (let i = n; i > 0; i--) {
|
||||
product *= i;
|
||||
}
|
||||
return product;
|
||||
}
|
||||
};
|
||||
|
||||
// This is another implementation of Factorial that uses recursion
|
||||
// THANKS to @ThirtyThreeB!
|
||||
const recursiveFactorial = function(n) {
|
||||
if (n===0){
|
||||
if (n === 0) {
|
||||
return 1;
|
||||
}
|
||||
return n * recursiveFactorial (n-1);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Exercise XX - fibonacci
|
||||
# Exercise XX - Fibonacci
|
||||
|
||||
Create a function that returns a specific member of the fibonacci sequence:
|
||||
Create a function that returns a specific member of the Fibonacci sequence:
|
||||
|
||||
> a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
|
||||
> A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
|
||||
|
||||
```javascript
|
||||
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const fibonacci = function(count) {
|
||||
if (count < 0) return "OOPS";
|
||||
if (count == 0) return 0;
|
||||
if (count === 0) return 0;
|
||||
let a = 0;
|
||||
let b = 1;
|
||||
for (let i = 1; i < count; i++) {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
# Find the Oldest
|
||||
|
||||
given an array of objects representing people with a birth and death year, return the oldest person.
|
||||
Given an array of objects representing people with a birth and death year, return the oldest person.
|
||||
|
||||
## Hints
|
||||
- You should return the whole person object, but the tests mostly just check to make sure the name is correct.
|
||||
- this can be done with a couple of chained array methods, or by using `reduce`.
|
||||
- One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today.
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ const findTheOldest = function(array) {
|
|||
const currentAge = getAge(currentPerson.yearOfBirth, currentPerson.yearOfDeath)
|
||||
return oldestAge < currentAge ? currentPerson : oldest
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const getAge = function(birth, death) {
|
||||
if (!death) {
|
||||
death = new Date().getFullYear();
|
||||
}
|
||||
return death - birth;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = findTheOldest
|
||||
module.exports = findTheOldest;
|
||||
|
|
|
@ -15,7 +15,7 @@ const books = [
|
|||
]
|
||||
```
|
||||
|
||||
your job is to write a function that takes the array and returns an array of titles:
|
||||
Your job is to write a function that takes the array and returns an array of titles:
|
||||
|
||||
```javascript
|
||||
getTheTitles(books) // ['Book','Book2']
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const getTheTitles = function(array) {
|
||||
return array.map(book => book.title)
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = getTheTitles
|
||||
module.exports = getTheTitles;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const helloWorld = function() {
|
||||
return 'Hello, World!'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = helloWorld
|
||||
module.exports = helloWorld;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const leapYears = function(year) {
|
||||
return year % 4 === 0 && ( year % 100 !== 0 || year % 400 == 0)
|
||||
}
|
||||
return year % 4 === 0 && ( year % 100 !== 0 || year % 400 === 0)
|
||||
};
|
||||
|
||||
module.exports = leapYears
|
||||
module.exports = leapYears;
|
||||
|
|
|
@ -8,7 +8,7 @@ const pigLatin = function(string) {
|
|||
return `${ending}${beginning}ay`;
|
||||
})
|
||||
.join(" ");
|
||||
}
|
||||
};
|
||||
|
||||
const firstVowelIndex = function(string) {
|
||||
const vowels = string.match(/[aeiou]/g);
|
||||
|
@ -16,6 +16,6 @@ const firstVowelIndex = function(string) {
|
|||
return string.indexOf(vowels[1]);
|
||||
}
|
||||
return string.indexOf(vowels[0]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = pigLatin
|
||||
module.exports = pigLatin;
|
|
@ -8,10 +8,9 @@ removeFromArray([1, 2, 3, 4], 3); // should remove 3 and return [1,2,4]
|
|||
|
||||
## Hints
|
||||
|
||||
the first test on this one is fairly easy, but there are a few things to think about(or google) here for the later tests:
|
||||
The first test on this one is fairly easy, but there are a few things to think about(or google) here for the later tests:
|
||||
|
||||
- how to remove a single element from an array
|
||||
- how to deal with multiple optional arguments in a javascript function
|
||||
- [Check this link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments). Scroll down to the bit about `Array.from` or the spread operator. - [Or this link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
|
||||
|
||||
|
||||
|
|
@ -5,6 +5,6 @@ const repeatString = function(word, times) {
|
|||
string += word
|
||||
}
|
||||
return string
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = repeatString
|
||||
module.exports = repeatString;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const reverseString = function(string) {
|
||||
return string.split('').reverse().join('')
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = reverseString
|
||||
module.exports = reverseString;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const ftoc = function(f) {
|
||||
return Math.round((f - 32) * (5/9) * 10) / 10
|
||||
}
|
||||
};
|
||||
|
||||
const ctof = function(c) {
|
||||
return Math.round(((c * 9/5) + 32) * 10) / 10
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ftoc,
|
||||
ctof
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue