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.
|
> 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
|
```javascript
|
||||||
caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!'
|
caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
const add = function(a, b) {
|
const add = function(a, b) {
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
};
|
||||||
|
|
||||||
const subtract = function(a, b) {
|
const subtract = function(a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
}
|
};
|
||||||
|
|
||||||
const sum = function(array) {
|
const sum = function(array) {
|
||||||
return array.reduce((total, current) => total + current, 0);
|
return array.reduce((total, current) => total + current, 0);
|
||||||
}
|
};
|
||||||
|
|
||||||
const multiply = function(array) {
|
const multiply = function(array) {
|
||||||
return array.length
|
return array.length
|
||||||
? array.reduce((accumulator, nextItem) => accumulator * nextItem)
|
? array.reduce((accumulator, nextItem) => accumulator * nextItem)
|
||||||
: 0;
|
: 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
const power = function(a, b) {
|
const power = function(a, b) {
|
||||||
return Math.pow(a, b);
|
return Math.pow(a, b);
|
||||||
}
|
};
|
||||||
|
|
||||||
const factorial = function(n) {
|
const factorial = function(n) {
|
||||||
if (n == 0) return 1;
|
if (n === 0) return 1;
|
||||||
let product = 1;
|
let product = 1;
|
||||||
for (let i = n; i > 0; i--) {
|
for (let i = n; i > 0; i--) {
|
||||||
product *= i;
|
product *= i;
|
||||||
}
|
}
|
||||||
return product;
|
return product;
|
||||||
}
|
};
|
||||||
|
|
||||||
// This is another implementation of Factorial that uses recursion
|
// This is another implementation of Factorial that uses recursion
|
||||||
// THANKS to @ThirtyThreeB!
|
// THANKS to @ThirtyThreeB!
|
||||||
|
@ -36,7 +36,7 @@ const recursiveFactorial = function(n) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return n * recursiveFactorial (n-1);
|
return n * recursiveFactorial (n-1);
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
add,
|
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
|
```javascript
|
||||||
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)
|
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const fibonacci = function(count) {
|
const fibonacci = function(count) {
|
||||||
if (count < 0) return "OOPS";
|
if (count < 0) return "OOPS";
|
||||||
if (count == 0) return 0;
|
if (count === 0) return 0;
|
||||||
let a = 0;
|
let a = 0;
|
||||||
let b = 1;
|
let b = 1;
|
||||||
for (let i = 1; i < count; i++) {
|
for (let i = 1; i < count; i++) {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
# Find the Oldest
|
# 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
|
## Hints
|
||||||
- You should return the whole person object, but the tests mostly just check to make sure the name is correct.
|
- 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`.
|
- 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.
|
- 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)
|
const currentAge = getAge(currentPerson.yearOfBirth, currentPerson.yearOfDeath)
|
||||||
return oldestAge < currentAge ? currentPerson : oldest
|
return oldestAge < currentAge ? currentPerson : oldest
|
||||||
})
|
})
|
||||||
}
|
};
|
||||||
|
|
||||||
const getAge = function(birth, death) {
|
const getAge = function(birth, death) {
|
||||||
if (!death) {
|
if (!death) {
|
||||||
death = new Date().getFullYear();
|
death = new Date().getFullYear();
|
||||||
}
|
}
|
||||||
return death - birth;
|
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
|
```javascript
|
||||||
getTheTitles(books) // ['Book','Book2']
|
getTheTitles(books) // ['Book','Book2']
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const getTheTitles = function(array) {
|
const getTheTitles = function(array) {
|
||||||
return array.map(book => book.title)
|
return array.map(book => book.title)
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = getTheTitles
|
module.exports = getTheTitles;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const helloWorld = function() {
|
const helloWorld = function() {
|
||||||
return 'Hello, World!'
|
return 'Hello, World!'
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = helloWorld
|
module.exports = helloWorld;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const leapYears = function(year) {
|
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`;
|
return `${ending}${beginning}ay`;
|
||||||
})
|
})
|
||||||
.join(" ");
|
.join(" ");
|
||||||
}
|
};
|
||||||
|
|
||||||
const firstVowelIndex = function(string) {
|
const firstVowelIndex = function(string) {
|
||||||
const vowels = string.match(/[aeiou]/g);
|
const vowels = string.match(/[aeiou]/g);
|
||||||
|
@ -16,6 +16,6 @@ const firstVowelIndex = function(string) {
|
||||||
return string.indexOf(vowels[1]);
|
return string.indexOf(vowels[1]);
|
||||||
}
|
}
|
||||||
return string.indexOf(vowels[0]);
|
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
|
## 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 remove a single element from an array
|
||||||
- how to deal with multiple optional arguments in a javascript function
|
- 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).
|
- [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
|
string += word
|
||||||
}
|
}
|
||||||
return string
|
return string
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = repeatString
|
module.exports = repeatString;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const reverseString = function(string) {
|
const reverseString = function(string) {
|
||||||
return string.split('').reverse().join('')
|
return string.split('').reverse().join('')
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = reverseString
|
module.exports = reverseString;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
const ftoc = function(f) {
|
const ftoc = function(f) {
|
||||||
return Math.round((f - 32) * (5/9) * 10) / 10
|
return Math.round((f - 32) * (5/9) * 10) / 10
|
||||||
}
|
};
|
||||||
|
|
||||||
const ctof = function(c) {
|
const ctof = function(c) {
|
||||||
return Math.round(((c * 9/5) + 32) * 10) / 10
|
return Math.round(((c * 9/5) + 32) * 10) / 10
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ftoc,
|
ftoc,
|
||||||
ctof
|
ctof
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in New Issue