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
# 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 |
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
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); |
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
'hello world' | |
"hello world" | |
123 | |
1.23 | |
-123 | |
false | |
true |
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
let a = [9, 2, 3]; | |
a.length | |
// a.push() | |
// a.pop() | |
// a.unshift() | |
// a.splice() | |
// a.slice() | |
// a.reverse() | |
// a.join() |
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
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]; |
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
// String to number | |
const str = '123'; | |
const num1 = parseInt(str); | |
const num2 = Number(str); | |
// Number to string | |
const n = 123; | |
const s = n.toString(); |
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
/****************** | |
* YOUR CODE HERE * | |
******************/ | |
// addAll([1, 2, 3]) | |
function addAll(numbers) { | |
let sum = 0; | |
for (const number of numbers) { | |
sum = sum + number; |
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
// ##### 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 ##### |
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 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]; |
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 getSum(a, b) { | |
// Determine which number is smaller and bigger | |
let smallest = a; | |
let biggest = b; | |
if (b < a) { | |
smallest = b; | |
biggest = a; | |
} | |
OlderNewer