Skip to content

Instantly share code, notes, and snippets.

@noximus
Created April 3, 2019 16:10
Show Gist options
  • Save noximus/f8edb000bb549430aad9515059789167 to your computer and use it in GitHub Desktop.
Save noximus/f8edb000bb549430aad9515059789167 to your computer and use it in GitHub Desktop.
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