Skip to content

Instantly share code, notes, and snippets.

# Returns the nth iteration of the fibonacci sequence
# n: 0 1 2 3 4 5 6
# output: 1 1 2 3 5 8 13
def fibonacci(n):
# Base case
if n == 0 or n == 1:
return 1
# Recursive case
const str = 'strings';
const num = 1.0;
const bool = false;
const arr = [1, 2, 3];
console.log(typeof str);
console.log(typeof num);
console.log(typeof bool);
console.log(typeof arr);
'hello world'
"hello world"
123
1.23
-123
false
true
let a = [9, 2, 3];
a.length
// a.push()
// a.pop()
// a.unshift()
// a.splice()
// a.slice()
// a.reverse()
// a.join()
let variable = 1;
const str = 'Coding bootcamp';
for (const letter of str) {
console.log(letter);
}
for (let i = 0; i < str.length; i++) {
const letter = str[i];
// String to number
const str = '123';
const num1 = parseInt(str);
const num2 = Number(str);
// Number to string
const n = 123;
const s = n.toString();
/******************
* YOUR CODE HERE *
******************/
// addAll([1, 2, 3])
function addAll(numbers) {
let sum = 0;
for (const number of numbers) {
sum = sum + number;
// ##### Introduction #####
//
// The below assignment will require NO functions
//
// Instead, our focus is going to be on console.logging the characters at certain indices of strings.
//
// ##### Challenges #####
function maxDiff(list) {
// If we get an empty list, just return 0
if (list.length === 0) {
return 0;
}
// Initialize biggest and smallest nums to the first item in the list
let biggestNum = list[0];
let smallestNum = list[0];
function getSum(a, b) {
// Determine which number is smaller and bigger
let smallest = a;
let biggest = b;
if (b < a) {
smallest = b;
biggest = a;
}