forked from semmypurewal/BeginningJavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.js
More file actions
130 lines (123 loc) · 3.84 KB
/
practice.js
File metadata and controls
130 lines (123 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// In one of the previous sections, we had an practice problem where you had to
// reverse a string. Do the same thing with an array, but use the `reduce` and
// `concat` methods to avoid local variables.
//
// reverse([ 1, 2, 3, 4, 5 ]);
// //=> [ 5, 4, 3, 2, 1 ]
//
// reverse([ "hello", "world" ]);
// //=> [ "world", "hello" ]
//
var reverse = function () {
};
// Did you know that you could have arrays within arrays? This is perfectly
// legal JavaScript:
//
// var nestedArray = [ 1, 2, [ 10, 20 ], 3, 4, 5 ];
//
// nestedArray[0];
// //=> 1
//
// nestedArray[1];
// //=> 2
//
// nestedArray[2];
// //=> [ 10, 20 ]
//
// nestedArray[2][0];
// //=> 10
//
// For this problem, write a function using `reduce` that "flattens" a possibly
// nested array into a single array.
//
// flatten(nestedArray);
// //=> [ 1, 2, 10, 20, 3, 4, 5 ]
//
// flatten([ 1, [2, 3], 4, [5, 6, 7], 8 ]);
// //=> [ 1, 2, 3, 4, 5, 6, 7, 8 ]
//
// You'll also want to use the `concat` method to make this work.
//
var flatten = function () {
};
// Using `range` and a chain of array methods, write a function that accepts a
// number `n` and returns the sum of all of the positive multiples of 3 and 5 that
// are smaller than or equal to `n`.
//
// sumOfMultiplesOf3And5(100);
// //=> 2418
//
// sumOfMultiplesOf3And5(50);
// //=> 593
//
// sumOfMultiplesOf3And5(0);
// //=> 0
//
var sumOfMultiplesOf3And5 = function () {
};
// Write a function called atLeastOneVowel that accepts a string and
// returns true if that word contains at least one vowel. Do not use a
// `for` loop or a `forEach` loop.
//
// atLeastOneVowel("hello");
// //=> true
//
// atLeastOneVowel("dry");
// //=> false
//
// atLeastOneVowel("sdfjkl");
// //=> false
//
var atLeastOneVowel = function () {
};
// Write a function that accepts a list of tweets, and returns the
// longest tweet that contains the word `awesome` or the empty string
// if no tweet contains the word awesome.
//
// logestAwesomeTweet([ "awesome", "longer tweet with awesome", "not awesome", "empty" ]);
// //=> "longer tweet with awesome"
//
// longestAwesomeTweet([ "hello", "world" ]);
// //=> ""
//
var longestAwesomeTweet = function () {
};
// Write a function that accepts an array of HTMLElements and returns an
// array of their content.
//
// elementsToContent(["<p>this is a paragraph</p>", "<li>list item</li>", "<a>link!</a>" ]);
// //=> [ "this is a paragraph", "list item", "link!" ]
//
// elementsToContent([ "<h1>This is an important heading!</h1>", "<h5>this is not as important</h5>" ]);
// //=> [ "This is an important heading!", "this is not as important" ]
//
var elementsToContent = function () {
};
// In a previous section, we created a function called `randUpTo` that
// returned a random integer up to an upper bound. Using that function
// along with the `range` function, write a method called
// `randomArray` that accepts two numbers, `length`, and `max`. It
// should return an array of length `length` that contains random
// numbers up to the value `max`.
//
// randomArray(10, 100);
// //=> [ 56, 32, 4, 92, 73, 75, 11, 10, 26, 4 ]
//
// randomArray(5, 10);
// //=> [ 2, 0, 3, 9, 10 ]
//
var randomArray = function () {
};
// Using the `randomNums` function from above, write a function called
// `randomElements` that accepts an array, and a number, `n` and
// returns a new array that consists of `n` random elements selected
// from the input array. Duplicates are allowed.
//
// randomElements([ "red", "orange", "yellow", "green", "blue", "purple", "gray", "black", "white" ], 5);
// //=> [ "green", "green", "blue", "orange", "black" ]
//
// randomElements([ "clubs", "diamonds", "hearts", "spades" ], 3);
// //=> [ "hearts", "diamonds", "hearts" ]
//
var randomElements = function () {
};