-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-06-2022.js
42 lines (25 loc) · 1.03 KB
/
11-06-2022.js
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
/* 8 Kyu - Welcome to the City
Create a method sayHello/say_hello/SayHello that takes as input a name, city, and state to welcome a person. Note that name will be an array consisting of one or more values that should be joined together with one space between each, and the length of the name array in test cases will vary.
Example:
sayHello(['John', 'Smith'], 'Phoenix', 'Arizona')
This example will return the string Hello, John Smith! Welcome to Phoenix, Arizona!
*/
//SOLUTION
function sayHello(name, city, state) {
return `Hello, ${name.join(' ')}! Welcome to ${city}, ${state}!`
}
/* 8 Kyu - Powers of 2
Complete the function that takes a non-negative integer n as input, and returns a list of all the powers of 2 with the exponent ranging from 0 to n ( inclusive ).
Examples
n = 0 ==> [1] # [2^0]
n = 1 ==> [1, 2] # [2^0, 2^1]
n = 2 ==> [1, 2, 4] # [2^0, 2^1, 2^2]
*/
//SOLUTION
function powersOfTwo(n){
let arr = [];
for (i = 0; i <= n; i++) {
arr.push(Math.pow(2, i));
}
return arr;
}