Created
April 3, 2019 16:10
-
-
Save noximus/f8edb000bb549430aad9515059789167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function perimeter(num) { | |
let a = 1, | |
b = 0, | |
temp, | |
arr = []; | |
while (num >= 0) { | |
temp = a; | |
a = a + b; | |
b = temp; | |
arr.push(b); | |
num--; | |
} | |
return arr.map(e => e * 4).reduce((a, b) => a + b); | |
} | |
console.log(perimeter(5)); // should be 80 | |
console.log(perimeter(7)); // should be 216 | |
console.log(perimeter(20)); // should be 114624 | |
console.log(perimeter(30)); // should be 14098308 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment