Skip to content

Commit d898c07

Browse files
committed
update comments.
1 parent dc06e99 commit d898c07

17 files changed

+125
-72
lines changed

arguments-optional.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
/*
22
Create a function that sums two arguments together.
3-
If only one argument is provided, then return a function that expects one argument and returns the sum.
3+
If only one argument is provided, then return a function that expects one argument
4+
and returns the sum.
45
56
For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.
67
*/
78

89
function addTogether() {
9-
const checkType = (number) => {
10-
if (typeof(number) === "number") {
10+
const checkType = number => {
11+
if (typeof number === "number") {
1112
return true;
1213
} else return false;
13-
}
14+
};
1415

1516
if (arguments.length > 1) {
1617
let x = arguments[0];
1718
let y = arguments[1];
18-
19-
if (checkType(x) && checkType(y)) return (x + y);
19+
20+
if (checkType(x) && checkType(y)) return x + y;
2021
} else if (arguments.length === 1) {
2122
let z = arguments[0];
2223

2324
if (checkType(arguments[0])) {
24-
return (arg2) => {
25-
if (checkType(arg2)) return (z + arg2);
26-
}
27-
}
25+
return arg2 => {
26+
if (checkType(arg2)) return z + arg2;
27+
};
28+
}
2829
}
2930
}
3031

convert-html-entities.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/*
2-
Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities.
2+
Convert the characters &, <, >, " (double quote), and ' (apostrophe),
3+
in a string to their corresponding HTML entities.
34
*/
45

56
function convertHTML(str) {
6-
str = str.replace(/&/g, "&amp;")
7-
str = str.replace(/</g, "&lt;")
8-
str = str.replace(/>/g, "&gt;")
9-
str = str.replace(/"/g, "&quot;")
10-
str = str.replace(/'/g, "&apos;")
7+
str = str.replace(/&/g, "&amp;");
8+
str = str.replace(/</g, "&lt;");
9+
str = str.replace(/>/g, "&gt;");
10+
str = str.replace(/"/g, "&quot;");
11+
str = str.replace(/'/g, "&apos;");
1112

1213
return str;
1314
}

diff-two-arrays.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
/*
2-
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
2+
Compare two arrays and return a new array with any items only found in one of the
3+
two given arrays, but not both.
4+
5+
In other words, return the symmetric difference of the two arrays.
36
*/
47

58
const filterArray = (arr, arr2) => {
6-
let newArray = arr.filter((value) => {
9+
let newArray = arr.filter(value => {
710
if (arr2.indexOf(value) < 0) return value;
811
});
912

1013
return newArray;
11-
}
14+
};
1215

1316
function diffArray(arr1, arr2) {
1417
var newArr = [...filterArray(arr2, arr1), ...filterArray(arr1, arr2)];
1518

1619
return newArr;
1720
}
1821

19-
diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
22+
diffArray(
23+
["andesite", "grass", "dirt", "pink wool", "dead shrub"],
24+
["diorite", "andesite", "grass", "dirt", "dead shrub"]
25+
);

dna-pairing.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
2+
The DNA strand is missing the pairing element. Take each character, get its pair,
3+
and return the results as a 2d array.
34
45
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
56
@@ -8,20 +9,20 @@ Return the provided character as the first element in each array.
89

910
const search = (char, pairs) => {
1011
switch (char) {
11-
case "T":
12-
pairs.push(["T", "A"]);
13-
break;
14-
case "A":
15-
pairs.push(["A", "T"]);
16-
break;
17-
case "C":
18-
pairs.push(["C", "G"]);
19-
break;
20-
case "G":
21-
pairs.push(["G", "C"]);
22-
break;
12+
case "T":
13+
pairs.push(["T", "A"]);
14+
break;
15+
case "A":
16+
pairs.push(["A", "T"]);
17+
break;
18+
case "C":
19+
pairs.push(["C", "G"]);
20+
break;
21+
case "G":
22+
pairs.push(["G", "C"]);
23+
break;
2324
}
24-
}
25+
};
2526

2627
function pairElement(str) {
2728
var pairs = [];

drop-it.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
2-
Given the array arr, iterate through and remove each element starting from the first element (the 0 index) until the function func returns true when the iterated element is passed through it.
2+
Given the array arr, iterate through and remove each element starting from
3+
the first element (the 0 index) until the function func returns true when the
4+
iterated element is passed through it.
35
*/
46

57
function dropElements(arr, func) {
@@ -15,4 +17,8 @@ function dropElements(arr, func) {
1517
return updatedArray;
1618
}
1719

18-
console.log(dropElements([1, 2, 3, 4], function(n) {return n >= 3; }));
20+
console.log(
21+
dropElements([1, 2, 3, 4], function(n) {
22+
return n >= 3;
23+
})
24+
);

everything-be-true.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
/*
2-
Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
2+
Check if the predicate (second argument) is truthy on all elements of a collection
3+
(first argument).
34
*/
45

56
function truthCheck(collection, pre) {
67
for (let i = 0; i < collection.length; i++) {
7-
if (!(collection[i][pre])) return false;
8+
if (!collection[i][pre]) return false;
89
}
910

1011
return true;
1112
}
1213

13-
console.log(truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"));
14+
console.log(
15+
truthCheck(
16+
[
17+
{ user: "Tinky-Winky", sex: "male" },
18+
{ user: "Dipsy", sex: "male" },
19+
{ user: "Laa-Laa", sex: "female" },
20+
{ user: "Po", sex: "female" }
21+
],
22+
"sex"
23+
)
24+
);

map-the-debris.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Return a new array that transforms the elements' average altitude into their orbital periods (in seconds).
2+
Return a new array that transforms the elements' average altitude into their
3+
orbital periods (in seconds).
34
45
The array will contain objects in the format {name: 'name', avgAlt: avgAlt}.
56
*/
@@ -9,16 +10,15 @@ function orbitalPeriod(arr) {
910
var earthRadius = 6367.4447;
1011

1112
for (let i = 0; i < arr.length; i++) {
12-
let orbitalPeriodCalc = (2 * Math.PI) * Math.sqrt(
13-
Math.pow(earthRadius + arr[i]['avgAlt'], 3) / GM
14-
)
13+
let orbitalPeriodCalc =
14+
2 * Math.PI * Math.sqrt(Math.pow(earthRadius + arr[i]["avgAlt"], 3) / GM);
1515

16-
delete arr[i]['avgAlt'];
16+
delete arr[i]["avgAlt"];
1717

18-
arr[i]['orbitalPeriod'] = Math.round(orbitalPeriodCalc);
18+
arr[i]["orbitalPeriod"] = Math.round(orbitalPeriodCalc);
1919
}
2020

2121
return arr;
2222
}
2323

24-
console.log(orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]));
24+
console.log(orbitalPeriod([{ name: "sputnik", avgAlt: 35873.5553 }]));

missing-letters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function fearNotLetter(str) {
99
let actualLetterCode = str.charCodeAt(i);
1010
let nextLetterCode = str.charCodeAt(i + 1);
1111

12-
if ((actualLetterCode + 1) != nextLetterCode) {
12+
if (actualLetterCode + 1 != nextLetterCode) {
1313
return String.fromCharCode(actualLetterCode + 1);
1414
}
1515
}

pig-latin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
Translate the provided string to pig latin.
33
4-
Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay".
4+
Pig Latin takes the first consonant (or consonant cluster) of an English word,
5+
moves it to the end of the word and suffixes an "ay".
56
67
If a word begins with a vowel you just add "way" to the end.
78
@@ -18,7 +19,7 @@ function translatePigLatin(str) {
1819
str = str.concat("way");
1920
} else if (globalVowels.test(str)) {
2021
for (let i = 0; i < str.length - 1; i++) {
21-
if (!(startVowel.test(str))) {
22+
if (!startVowel.test(str)) {
2223
str = str.slice(1, str.length).concat(str.charAt(0));
2324
} else {
2425
break;

search-and-replace.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Perform a search and replace on the sentence using the arguments provided and return the new sentence.
2+
Perform a search and replace on the sentence using the arguments provided and return
3+
the new sentence.
34
45
First argument is the sentence to perform the search and replace on.
56
@@ -8,12 +9,14 @@ Second argument is the word that you will be replacing (before).
89
Third argument is what you will be replacing the second argument with (after).
910
1011
Note
11-
Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog"
12-
*/
1312
13+
Preserve the case of the first character in the original word when you are replacing it.
14+
For example if you mean to replace the word "Book" with the word "dog",
15+
it should be replaced as "Dog"
16+
*/
1417

1518
function myReplace(str, before, after) {
16-
let regex = /^[A-Z]/
19+
let regex = /^[A-Z]/;
1720

1821
if (regex.test(before)) {
1922
after = after.charAt(0).toUpperCase() + after.slice(1);

seek-and-destroy.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
2-
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
2+
You will be provided with an initial array (the first argument in the destroyer function),
3+
followed by one or more arguments. Remove all elements from the initial array that are of
4+
the same value as these arguments.
35
46
Note
57
You have to use the arguments object.
@@ -11,7 +13,7 @@ const destroy = (arr, number) => {
1113
});
1214

1315
return arr;
14-
}
16+
};
1517

1618
function destroyer(arr) {
1719
let keys = Object.keys(arguments);

smallest-common-multiple.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.
2+
Find the smallest common multiple of the provided parameters that can be evenly divided by both,
3+
as well as by all sequential numbers in the range between these parameters.
34
*/
45

56
function smallestCommons(arr) {
@@ -21,4 +22,4 @@ function smallestCommons(arr) {
2122
}
2223
}
2324

24-
smallestCommons([1,5]);
25+
smallestCommons([1, 5]);

sorted-union.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
/*
2-
Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.
2+
Write a function that takes two or more arrays and returns a new array of unique values
3+
in the order of the original provided arrays.
34
4-
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
5+
In other words, all values present from all arrays should be included in their original
6+
order, but with no duplicates in the final array.
57
6-
The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.
8+
The unique numbers should be sorted by their original order, but the final array should not
9+
be sorted in numerical order.
710
*/
811

9-
function onlyUnique(value, index, self) {
10-
return self.indexOf(value) === index;
12+
function onlyUnique(value, index, self) {
13+
return self.indexOf(value) === index;
1114
}
1215

1316
function uniteUnique(arr) {
14-
let unique = []
17+
let unique = [];
1518

1619
for (let key in arguments) {
1720
unique.push(...arguments[key]);
1821
}
19-
22+
2023
unique = unique.filter(onlyUnique);
2124

2225
return unique;

sum-all-numbers-in-a-range.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first.
2+
We'll pass you an array of two numbers. Return the sum of those two numbers plus
3+
the sum of all the numbers between them. The lowest number will not always come first.
34
*/
45

56
function sumAll(arr) {

sum-all-odd-fibonacci-numbers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num.
2+
Given a positive integer num, return the sum of all odd Fibonacci numbers that are
3+
less than or equal to num.
34
*/
45

5-
66
function sumFibs(num) {
77
var previousNumber = 0;
88
var currentNumber = 1;

sum-all-primes.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/*
2-
A prime number is a whole number greater than 1 with exactly two divisors: 1 and itself. For example, 2 is a prime number because it is only divisible by 1 and 2. In contrast, 4 is not prime since it is divisible by 1, 2 and 4.
2+
A prime number is a whole number greater than 1 with exactly two divisors: 1 and
3+
itself. For example, 2 is a prime number because it is only divisible by 1 and 2.
4+
5+
In contrast, 4 is not prime since it is divisible by 1, 2 and 4.
36
*/
47

58
const isPrime = number => {
69
for (let i = 2, s = Math.sqrt(number); i <= s; i++) {
710
if (number % i === 0) return false;
811
}
9-
12+
1013
return number > 1;
11-
}
14+
};
1215

1316
function sumPrimes(num) {
1417
let result = 0;

wherefore-art-thou.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/*
2-
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
2+
Make a function that looks through an array of objects (first argument) and returns
3+
an array of all objects that have matching name and value pairs (second argument).
4+
5+
Each name and value pair of the source object has to be present in the object from
6+
the collection if it is to be included in the returned array.
37
*/
48

59
function whatIsInAName(collection, source) {
@@ -21,4 +25,13 @@ function whatIsInAName(collection, source) {
2125
return arr;
2226
}
2327

24-
console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }));
28+
console.log(
29+
whatIsInAName(
30+
[
31+
{ first: "Romeo", last: "Montague" },
32+
{ first: "Mercutio", last: null },
33+
{ first: "Tybalt", last: "Capulet" }
34+
],
35+
{ last: "Capulet" }
36+
)
37+
);

0 commit comments

Comments
 (0)