Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
perimeter_of_squares_in_a_rectangle

ruby

def perimeter(n)
  num = [0,1]
  i = 0
  until i == n do
    num << num[i] + num [i+1]
    i += 1
  end
  num.sum * 4
end

js

function perimeter(n) {
  let arr = [0,1];
  for(let i = 0; i < n ; i++) {
    arr.push(arr[i] + arr[i+1]);
  }
  return 4 * arr.reduce((sum, num) => sum + num, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.