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
def collatz(n) | |
# set an empty arry to contain the values of the sequence | |
ary = [] | |
# set initial index value to 0 | |
index = 0 | |
# start by pushing n into the array | |
ary.push(n) | |
# loop until the array includes the number 1, i.e. until the sequence is complete | |
until ary.include?(1) |
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
def recursive_fib(n) | |
# sets the first two values (0 and 1) by default | |
if n < 2 | |
return n | |
# if n is greater than or equal to 2, the nth number in the fibonacci | |
# is the sum of the function called on n-1 and the function called on | |
# n-2 | |
else | |
return recursive_fib(n-1) + recursive_fib(n-2) | |
end |
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
"use strict"; | |
var _ = { | |
// Implements: | |
// https://lodash.com/docs#map | |
map: (array, callback) => { | |
return callback(array); | |
} | |
} |
NewerOlder