Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 (typeofnumber === "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);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /