Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TheOdinProject/javascript-exercises
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: Smabian/javascript-exercises
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 13 commits
  • 23 files changed
  • 1 contributor

Commits on Feb 11, 2024

  1. Copy the full SHA
    5321897 View commit details
  2. Copy the full SHA
    03f6338 View commit details
  3. Copy the full SHA
    7f5c942 View commit details
  4. Copy the full SHA
    54df9a4 View commit details
  5. Copy the full SHA
    3fbf4cb View commit details
  6. Complete Exercise #5 | 05_sumAll

    Smabian committed Feb 11, 2024
    Copy the full SHA
    e8112c5 View commit details
  7. Copy the full SHA
    50b27dd View commit details
  8. Copy the full SHA
    b9191b2 View commit details

Commits on Feb 17, 2024

  1. Copy the full SHA
    a508768 View commit details
  2. Copy the full SHA
    014886f View commit details
  3. Copy the full SHA
    5875b7d View commit details
  4. Copy the full SHA
    490c74a View commit details
  5. Copy the full SHA
    81e12a0 View commit details
2 changes: 1 addition & 1 deletion 01_helloWorld/helloWorld.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const helloWorld = function() {
return ''
return 'Hello, World!'
};

module.exports = helloWorld;
11 changes: 10 additions & 1 deletion 02_repeatString/repeatString.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const repeatString = function() {
const repeatString = function(text, repeat) {
let outputText = "";

if(repeat < 0){
outputText = "ERROR";
}

for(i=repeat;i>0;i--) {
outputText += text;
}
return outputText;
};

// Do not edit below this line
12 changes: 6 additions & 6 deletions 02_repeatString/repeatString.spec.js
Original file line number Diff line number Diff line change
@@ -4,19 +4,19 @@ describe('repeatString', () => {
test('repeats the string', () => {
expect(repeatString('hey', 3)).toEqual('heyheyhey');
});
test.skip('repeats the string many times', () => {
test('repeats the string many times', () => {
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
});
test.skip('repeats the string 1 times', () => {
test('repeats the string 1 times', () => {
expect(repeatString('hey', 1)).toEqual('hey');
});
test.skip('repeats the string 0 times', () => {
test('repeats the string 0 times', () => {
expect(repeatString('hey', 0)).toEqual('');
});
test.skip('returns ERROR with negative numbers', () => {
test('returns ERROR with negative numbers', () => {
expect(repeatString('hey', -1)).toEqual('ERROR');
});
test.skip('repeats the string a random amount of times', function () {
test('repeats the string a random amount of times', function () {
/*The number is generated by using Math.random to get a value from between
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
equals a number between 0 to 999 (this number will change everytime you run
@@ -31,7 +31,7 @@ describe('repeatString', () => {
was randomly generated. */
expect(repeatString('hey', number).match(/(hey)/g).length).toEqual(number);
});
test.skip('works with blank strings', () => {
test('works with blank strings', () => {
expect(repeatString('', 10)).toEqual('');
});
});
10 changes: 9 additions & 1 deletion 03_reverseString/reverseString.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
const reverseString = function() {
const reverseString = function(initialString) {
let reverseString = "";
let stringLength = initialString.length;

for(i=stringLength; i>=0; i--) {
reverseString += initialString.charAt(i);
}

return reverseString;

};

6 changes: 3 additions & 3 deletions 03_reverseString/reverseString.spec.js
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@ describe('reverseString', () => {
expect(reverseString('hello')).toEqual('olleh');
});

test.skip('reverses multiple words', () => {
test('reverses multiple words', () => {
expect(reverseString('hello there')).toEqual('ereht olleh')
})

test.skip('works with numbers and punctuation', () => {
test('works with numbers and punctuation', () => {
expect(reverseString('123! abc!')).toEqual('!cba !321')
})
test.skip('works with blank strings', () => {
test('works with blank strings', () => {
expect(reverseString('')).toEqual('')
})
});
11 changes: 10 additions & 1 deletion 04_removeFromArray/removeFromArray.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const removeFromArray = function() {
const removeFromArray = function(initialArray, ...removeItem) {

for (i=0; i <= removeItem.length; i++) {
let index = initialArray.indexOf(removeItem[i]);
if (index > -1) {
initialArray.splice(index,1);
i--;
}
}

return initialArray;
};

// Do not edit below this line
14 changes: 7 additions & 7 deletions 04_removeFromArray/removeFromArray.spec.js
Original file line number Diff line number Diff line change
@@ -4,25 +4,25 @@ describe('removeFromArray', () => {
test('removes a single value', () => {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
});
test.skip('removes multiple values', () => {
test('removes multiple values', () => {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
});
test.skip('removes multiple of the same value', () => {
test('removes multiple of the same value', () => {
expect(removeFromArray([1, 2, 2, 3], 2)).toEqual([1, 3]);
});
test.skip('ignores non present values', () => {
test('ignores non present values', () => {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
});
test.skip('ignores non present values, but still works', () => {
test('ignores non present values, but still works', () => {
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
});
test.skip('can remove all values', () => {
test('can remove all values', () => {
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
});
test.skip('works with strings', () => {
test('works with strings', () => {
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
});
test.skip('only removes same type', () => {
test('only removes same type', () => {
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
});
});
22 changes: 21 additions & 1 deletion 05_sumAll/sumAll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
const sumAll = function() {
const sumAll = function(number1, number2) {

let sumAll = 0;
let smallNumber;
let largeNumber;

if(number1 <= 0 || number2 <= 0 || "number" !== typeof number1 || "number" !== typeof number2 ) {
return sumAll = "ERROR";
}

if(number1 < number2) {
smallNumber = number1;
largeNumber = number2;
} else {
smallNumber = number2;
largeNumber = number1;
}

for(i=smallNumber; i <= largeNumber; i++) {
sumAll += i;
}
return sumAll;
};

// Do not edit below this line
10 changes: 5 additions & 5 deletions 05_sumAll/sumAll.spec.js
Original file line number Diff line number Diff line change
@@ -4,19 +4,19 @@ describe('sumAll', () => {
test('sums numbers within the range', () => {
expect(sumAll(1, 4)).toEqual(10);
});
test.skip('works with large numbers', () => {
test('works with large numbers', () => {
expect(sumAll(1, 4000)).toEqual(8002000);
});
test.skip('works with larger number first', () => {
test('works with larger number first', () => {
expect(sumAll(123, 1)).toEqual(7626);
});
test.skip('returns ERROR with negative numbers', () => {
test('returns ERROR with negative numbers', () => {
expect(sumAll(-10, 4)).toEqual('ERROR');
});
test.skip('returns ERROR with non-number parameters', () => {
test('returns ERROR with non-number parameters', () => {
expect(sumAll(10, "90")).toEqual('ERROR');
});
test.skip('returns ERROR with non-number parameters', () => {
test('returns ERROR with non-number parameters', () => {
expect(sumAll(10, [90, 1])).toEqual('ERROR');
});
});
10 changes: 9 additions & 1 deletion 06_leapYears/leapYears.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
const leapYears = function() {
const leapYears = function(year) {

if (year % 4 === 0 && year % 100 !== 0) {
return true;
} else if (year % 4 === 0 && year % 400 === 0) {
return true;
} else {
return false;
}

};

10 changes: 5 additions & 5 deletions 06_leapYears/leapYears.spec.js
Original file line number Diff line number Diff line change
@@ -4,19 +4,19 @@ describe('leapYears', () => {
test('works with non century years', () => {
expect(leapYears(1996)).toBe(true);
});
test.skip('works with non century years', () => {
test('works with non century years', () => {
expect(leapYears(1997)).toBe(false);
});
test.skip('works with ridiculously futuristic non century years', () => {
test('works with ridiculously futuristic non century years', () => {
expect(leapYears(34992)).toBe(true);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(1900)).toBe(false);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(1600)).toBe(true);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(700)).toBe(false);
});
});
13 changes: 11 additions & 2 deletions 07_tempConversion/tempConversion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
const convertToCelsius = function() {
const convertToCelsius = function(fahrenheit) {

let celsius = (fahrenheit - 32) * (5/9);
celsius = Math.round(celsius * 10)/10;
return celsius;
};

const convertToFahrenheit = function() {
const convertToFahrenheit = function(celsius) {

let fahrenheit = (celsius * 9/5) + 32;
fahrenheit = Math.round(fahrenheit * 10)/10;
return fahrenheit;

};

// Do not edit below this line
10 changes: 5 additions & 5 deletions 07_tempConversion/tempConversion.spec.js
Original file line number Diff line number Diff line change
@@ -4,22 +4,22 @@ describe('convertToCelsius', () => {
test('works', () => {
expect(convertToCelsius(32)).toEqual(0);
});
test.skip('rounds to 1 decimal', () => {
test('rounds to 1 decimal', () => {
expect(convertToCelsius(100)).toEqual(37.8);
});
test.skip('works with negatives', () => {
test('works with negatives', () => {
expect(convertToCelsius(-100)).toEqual(-73.3);
});
});

describe('convertToFahrenheit', () => {
test.skip('works', () => {
test('works', () => {
expect(convertToFahrenheit(0)).toEqual(32);
});
test.skip('rounds to 1 decimal', () => {
test('rounds to 1 decimal', () => {
expect(convertToFahrenheit(73.2)).toEqual(163.8);
});
test.skip('works with negatives', () => {
test('works with negatives', () => {
expect(convertToFahrenheit(-10)).toEqual(14);
});
});
35 changes: 23 additions & 12 deletions 08_calculator/calculator.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
const add = function() {

const add = function(a, b) {
return a + b;
};

const subtract = function() {

const subtract = function(a, b) {
return a - b;
};

const sum = function() {

const sum = function(arr) {
if (arr === undefined || arr.length == 0) {
return 0;
}
return arr.reduce((sum, first) => sum += first);
};

const multiply = function() {

const multiply = function(arr) {
return arr.reduce((sum, first) => sum = sum * first);
};

const power = function() {

const power = function(a, b) {
return a ** b;
};

const factorial = function() {

const factorial = function(a) {
if (a === 0 || a === 1) {
return 1;
} else {
let sum = 1;
for (i = a; i>0; i--){
sum = sum * i;
}
return sum;
}
};

// Do not edit below this line
Loading