-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathloudFall.js
41 lines (28 loc) · 1.11 KB
/
loudFall.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
/*
Mr. despair wants to jump off Dutch act, So he came to the top of a building.
Scientific research shows that a man jumped from the top of the roof, when the floor more than 6, the person will often die in an instant; When the floor is less than or equal to 6, the person will not immediately die, he would scream. (without proof)
Input: floor, The height of the building (floor)
Output: a string, The voice of despair(When jumping Dutch act)
Example:
sc(2) should return "Aa~ Pa! Aa!"
It means:
Mr. despair jumped from the 2 floor, the voice is "Aa~"
He fell on the ground, the voice is "Pa!"
He did not die immediately, and the final voice was "Aa!"
sc(6) should return "Aa~ Aa~ Aa~ Aa~ Aa~ Pa! Aa!"
sc(7) should return "Aa~ Aa~ Aa~ Aa~ Aa~ Aa~ Pa!"
sc(10) should return "Aa~ Aa~ Aa~ Aa~ Aa~ Aa~ Aa~ Aa~ Aa~ Pa!"
if floor<=1, Mr. despair is safe, return ""
*/
//Answer//
function sc(floor){
if(floor <= 1) return "";
return 'Aa~ '.repeat(floor-1) + 'Pa!' + (floor<=6 ? ' Aa!': '');
}
//OR//
function sc(f){
if(f<=1){return ''}else{
let A = 'Aa~ '.repeat(f-1)
if(f<=6){return A+'Pa! Aa!'}else{return A+'Pa!'}
}
}