Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Osborne authored and Kevin Osborne committed Sep 22, 2017
0 parents commit 6f17375
Show file tree
Hide file tree
Showing 123 changed files with 3,272 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions Chapter 1 - Fundamentals/addSevenToMost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Build function that accepts array. Return a new array with all values except first, adding 7 to each. Do not alter the orignal array.

function addSevenToMost(arr){
var newarr = [];
var i = 1;
while (i < arr.length){
newarr[i-1] = arr[i]+7;
i++;
}
console.log(newarr);
}

addSevenToMost([10,20,30,40,50]);
18 changes: 18 additions & 0 deletions Chapter 1 - Fundamentals/alwaysHungry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Create a function that accepts an array, and prints "yummy" each time one of the values is equal to "food". If no array elements are "food", then print "i'm hungry" once.

function alwaysHungry(arr){
var count = 0;
var i = 0;
while (i < arr.length){
if(arr[i] == "food"){
console.log("yummy");
count++;
}
i++;
}
if(count == 0){
console.log("I'm Hungry");
}
}

alwaysHungry([2, 4]);
12 changes: 12 additions & 0 deletions Chapter 1 - Fundamentals/biggieSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Given an array, write a function that changes all positive numbers in the array to "big". Example: makeItBig([-1,3,5,-5]) returns that same array, changed to [-1, "big", "big", -5].

function biggieSize(arr){
for(var i = 0; i < arr.length; i++){
if(arr[i] >= 0){
arr[i] = "Big";
}
}
console.log(arr);
}

biggieSize([-1,3,5,-5])
11 changes: 11 additions & 0 deletions Chapter 1 - Fundamentals/celsiusToFahrenheit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Create celsiusToFahrenheit (cDegrees) that accepts number of degrees Celsius, and returns the equivalent temperature express in Fahrenheit degrees.

function celsiusToFahrenheit(cDegree){

var fDegree = 9/5*(cDegree)+32;
fDegree = fDegree.toFixed(2);
console.log(fDegree + " Fahrenheit");
return fDegree;
}

celsiusToFahrenheit(20);
13 changes: 13 additions & 0 deletions Chapter 1 - Fundamentals/countDown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Create a function that accepts a number as an input. Return a new array that counts down by one, from the number (as array's zero'th element) down to 0 (as the last element). How long is this array?

function countDown(num){
arr = [];
while(num != -1){
arr.push(num);
num--;
}
console.log(arr.length);
return arr.length;
}

countDown(10);
14 changes: 14 additions & 0 deletions Chapter 1 - Fundamentals/countPositives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Given array of numbers, create function to replace last value with number of positive values. Example, countPositive([-1, 1, 1, 1]) changes array to [-1,1,1,3] and return it.

function countPositive(arr){
var count = 0;
for (var i = 0; i < arr.length; i++){
if(arr[i] >= 0){
count++;
}
}
arr[arr.length-1] = count;
return arr;
}

console.log(countPositive([-1, -4, 4, 3, 2, 6, -9]));
11 changes: 11 additions & 0 deletions Chapter 1 - Fundamentals/doubleVision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Given array, create a function to return a new array where each value in the orignal has been doubled. Calling double ([1, 2, 3]) should return [2,4,6] without changing orignal.

function doubleVision(arr){
var newarr = [];
for (var i = 0; i < arr.length; i++){
newarr[i] = arr[i] * 2;
}
console.log(newarr);
}

doubleVision([2,4,8,12])
16 changes: 16 additions & 0 deletions Chapter 1 - Fundamentals/evensAndOdds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Create a function that accepts an array. Every time that array has three odd values in a row, print "That is odd!". Every time the array has three evens in a row, print "Even more so!".

function evensAndOdds(arr){
for (var i = 0; i < arr.length; i++){
if(arr[i] && arr[i+1] && arr[i+2]){
if(arr[i]%2==0 && arr[i+1]%2==0 && arr[i+2]%2==0 ) {
console.log("Even more so!");
}
if(arr[i] % 2 != 0 && arr[i+1] % 2 != 0 && arr[i+2] != 0){
console.log("That's odd!");
}
}
}
}

evensAndOdds([2,2,2,3,3,3]);
11 changes: 11 additions & 0 deletions Chapter 1 - Fundamentals/fahrenheitToCelsius.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Kelvin wants to convert between temperature scales. Create fahrenheitToCelsius(fDegree) that accepts a number of degrees in Fahrenheit, and returns the equivalent temperature as expressed in Celsius degrees. For review, Fahrenheit = (9.5 * Celsius) + 32.

function fahrenheitToCelsius(fDegree){

var cDegree = 5/9*(fDegree-32);
cDegree = cDegree.toFixed(2);
console.log(cDegree + " Celsius");
return cDegree;
}

fahrenheitToCelsius(75);
27 changes: 27 additions & 0 deletions Chapter 1 - Fundamentals/findFahrenheitandCelsiusEquate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


function findFahrenheitandCelsiusEquate(cDegree){

while(true){
if(celsiusToFahrenheitMatch(cDegree) === true){
break;
}
else{
cDegree--;
}
}
}

function celsiusToFahrenheitMatch(cDegree){

var fDegree = 9/5*(cDegree)+32;
fDegree = fDegree.toFixed(2);
if(fDegree == cDegree){
console.log(fDegree + " Fahrenheit; " + cDegree + "Celsius");
return true;
}
console.log(cDegree);
return cDegree;
}

findFahrenheitandCelsiusEquate(50);
14 changes: 14 additions & 0 deletions Chapter 1 - Fundamentals/firstPlusLength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Given an array, return the sum of the first value in the array, plus the array's length. What happens if the array's first value is not a number, but a string (like "what?") or a boolean (like false).

function firstPlusLength(arr){

var sum = 0;

if (Number.isInteger(arr[0]) && Number.isInteger(arr.length)){
sum = arr[0] + arr.length;
}
console.log(sum);
}

firstPlusLength(['Hello',5,11]);
firstPlusLength([10,5,11]);
18 changes: 18 additions & 0 deletions Chapter 1 - Fundamentals/fitTheFirstValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Your function should accept an array. If value at [0] is greater than array's length, print "Too big!"; if the value is [0] is less than array's length, print "Too small!"; otherwise print "Just right!"

function fitTheFirstValue(arr){

switch(true){
case (arr[0] > arr.length):
console.log("Too big!")
break;
case (arr[0] < arr.length):
console.log("Too small!")
break;
case (arr[0] == arr.length):
console.log("Just right!")
break;
}
}

fitTheFirstValue([2, 100]);
13 changes: 13 additions & 0 deletions Chapter 1 - Fundamentals/incrementTheSeconds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Given arr, add 1 to odd elements ([1], [3], etc. console.log all values and return arr)

function incrementTheSeconds(arr){
for (var i = 0; i < arr.length; i++){
if(arr[i] % 2 != 0){
arr[i]+= 1;
}
}
console.log(arr);
return arr;
}

incrementTheSeconds([1,2,3,4,5,6,7,8,9,10]);
13 changes: 13 additions & 0 deletions Chapter 1 - Fundamentals/onlyKeepTheLastFew.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Stan learned something today: that directly decrementing an array's .length immediately shortens it by that amount. Given array arr and number x, remove all except the last x elements, and return arr (changed and shorten). Given ([2,4,6,8,10], 3), change the given array to [6,8,10] and return it.

function onlyKeepTheLastFew(arr, x){
if(x > arr.length-1){
console.log("x must be equal to or less than the length of the array");
}
else{
var sliced = arr.slice(arr.length-1-x, arr.length-1);
console.log(sliced);
return sliced;
}
}
onlyKeepTheLastFew([2,4,6,8,10],8);
18 changes: 18 additions & 0 deletions Chapter 1 - Fundamentals/outlookNegative.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Given an array, create and return a new one containing all the values of the provided array, made negative (not simply multiplied by -1). Given [1, -3,5], return [-1,-3,-5].

function outlookNegative(arr){
var newarr = [];
var i = 0;
while (i < arr.length){
if(arr[i] > 0){
newarr[i] = arr[i] * -1;
}
else{
newarr[i] = arr[i];
}
i++;
}
console.log(newarr);
}

outlookNegative([5,6,-4,3]);
14 changes: 14 additions & 0 deletions Chapter 1 - Fundamentals/previousLengths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// You are passed an array containing strings. Working within that same array, replace each string with a number -- the length of the string at previous array index - and return the array.

function previousLengths(arr){
var len = 0;
var temp = arr[0];
for (var i = 1; i < arr.length; i++){
len = temp.length;
temp = arr[i];
arr[i] = len;
}
console.log(arr);
}

previousLengths(['Washington', 'Oregon', 'California'])
10 changes: 10 additions & 0 deletions Chapter 1 - Fundamentals/printAndReturn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Your function will receive an array with two numbers. Print the first value, and return the second.

function printAndReturn(numA, numB){

console.log(numA);
return numB;

}

printAndReturn(10, 20);
19 changes: 19 additions & 0 deletions Chapter 1 - Fundamentals/printLowReturnHigh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Create a function that takes array of numbers. THe funciton should print the lowest value in the array, and return the highest value in the array.

function printLowReturnHigh(arr){

var low = arr[0];
var high = arr[0];
for( var i = 0; i < arr.length; i++){
if( low > arr[i]){
low = arr[i];
}
else {
high = arr[i];
}
}
console.log("Low Value is " + low + " High Value is " + high);
return high;
}

printLowReturnHigh([30, 40, 20, 54, 4])
14 changes: 14 additions & 0 deletions Chapter 1 - Fundamentals/printOneRetunAnother.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Build a function that takes array of numbers. The function should print second-to-last value in the array, and return first odd value in the array.

function printOneReturnAnother(arr){

console.log(arr[arr.length-2])

for (var i = 0; i < arr.length; i++){
if(arr[i] % 2 != 0){
return arr[i];
}
}
}

console.log(printOneReturnAnother([2,2,3,5,7,9]))
15 changes: 15 additions & 0 deletions Chapter 1 - Fundamentals/reverseArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Given array, wrtie a function that reverses values, in-place. Example: reverse ([3,1,6,4,2]) returns same array, containing ([2,4,6,1,3]).

function reverseArray(arr){
var temp;
var i = 0;
while(i < Math.floor(arr.length/2)){
temp = arr[i];
arr[i] = arr[arr.length-1-i]
arr[arr.length-1-i] = temp;
i++;
}
console.log(arr);
}

reverseArray([1,2,3,4,5])
12 changes: 12 additions & 0 deletions Chapter 1 - Fundamentals/scaleTheArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Given array arr and number num, multiply each arr value by num, and return the changed arr.

function scaleTheArray(arr, num){
var i = 0;
while(i < arr.length){
arr[i] *= num;
i++;
}
console.log(arr);
}

scaleTheArray([1,2,3,4,5], 10);
16 changes: 16 additions & 0 deletions Chapter 1 - Fundamentals/swapTowardTheCenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Given array, swap first and last, third and third-to-last, etc. Input [true, 42, "Ada", 2, "pizza"] becomes ["pizza", 42, "Ada", 2, true]. Change [1,2,3,4,5,6] to [6,2,4,3,5,1].

function swapTowardTheCenter(arr){
var temp;
var i = 0;
while(i < Math.floor(arr.length/2)){
temp = arr[i];
arr[i] = arr[arr.length-1-i];
arr[arr.length-1-i] = temp;
i = i+3;
}
console.log(arr);
}

swapTowardTheCenter([1,2,3,4,5,6]);
swapTowardTheCenter([true, 42, "Ada", 2, "pizza"]);
18 changes: 18 additions & 0 deletions Chapter 1 - Fundamentals/thisLengthThatValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Given two numbers, return array of length num1 with each value num2. Print "Jinx!" if they are the same.

function thisLengthThatValue(num1, num2){

if(num1 == num2){
console.log("Jinx!");
}

var arr = [];
arr.length = num1;
for (var i = 0; i < arr.length; i++){
arr[i] = num2;
}

console.log(arr);
}

thisLengthThatValue(2, 2);
Loading

0 comments on commit 6f17375

Please sign in to comment.