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: kk0425/javascript-exercises
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 11 commits
  • 21 files changed
  • 1 contributor

Commits on Nov 29, 2023

  1. first solution

    kk0425 committed Nov 29, 2023
    Copy the full SHA
    0367baf View commit details

Commits on Dec 18, 2023

  1. exercise 2 solution

    kk0425 committed Dec 18, 2023
    Copy the full SHA
    40ab823 View commit details
  2. exercise 3

    kk0425 committed Dec 18, 2023
    Copy the full SHA
    8ac401e View commit details

Commits on Dec 29, 2023

  1. lesson 4 complete

    kk0425 committed Dec 29, 2023
    Copy the full SHA
    80d5dc7 View commit details

Commits on Dec 31, 2023

  1. challenge 5 solution

    kk0425 committed Dec 31, 2023
    Copy the full SHA
    7293256 View commit details
  2. lesson 6 solution

    kk0425 committed Dec 31, 2023
    Copy the full SHA
    16c2535 View commit details
  3. solution 6 solution

    kk0425 committed Dec 31, 2023
    Copy the full SHA
    09f7431 View commit details

Commits on Jan 1, 2024

  1. lesson 8 solution

    kk0425 committed Jan 1, 2024
    Copy the full SHA
    db43a2c View commit details

Commits on Jan 2, 2024

  1. lesson 9 solution

    kk0425 committed Jan 2, 2024
    Copy the full SHA
    34984e8 View commit details
  2. lesson 8 solution

    kk0425 committed Jan 2, 2024
    Copy the full SHA
    0d3ec62 View commit details

Commits on Jan 4, 2024

  1. lesson 11 solution

    kk0425 committed Jan 4, 2024
    Copy the full SHA
    5d94fcb 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;
12 changes: 10 additions & 2 deletions 02_repeatString/repeatString.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const repeatString = function() {

const repeatString = function(string, num) {
if (num < 0) {
return "ERROR";
}

let strOutput = '';
for (let i = 0; i < num; i++) {
strOutput += string;
}
return strOutput;
};

// 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('');
});
});
9 changes: 7 additions & 2 deletions 03_reverseString/reverseString.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const reverseString = function() {

const reverseString = function(str) {
const splitStr = str.split('');
let reversedStr = '';
for (let i = splitStr.length - 1; i >= 0; i--) {
reversedStr += splitStr[i];
}
return reversedStr;
};

// Do not edit below this line
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('')
})
});
28 changes: 26 additions & 2 deletions 04_removeFromArray/removeFromArray.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
const removeFromArray = function() {
/*
function removeFromArray(array, ...values) {
return array.filter(arrayValue => {
for (const value of values) {
if (value === arrayValue) {
return false;
}
}
return true;
})
}
*/

};
function removeFromArray(numbers, ...removeValues) {
const result = [];
for (const number of numbers) {
let numberInList = false;
for (const removeValue of removeValues) {
if (removeValue === number) {
numberInList = true;
break;
}
}
if (!numberInList) result.push(number);
}
return result;
}

// Do not edit below this line
module.exports = removeFromArray;
14 changes: 7 additions & 7 deletions 04_removeFromArray/removeFromArray.spec.js
Original file line number Diff line number Diff line change
@@ -2,24 +2,24 @@ const removeFromArray = require('./removeFromArray')

describe('removeFromArray', () => {
test('removes a single value', () => {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
expect(removeFromArray([0, 1, 2, 3, 4], 3)).toEqual([0, 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('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]);
});
});
13 changes: 11 additions & 2 deletions 05_sumAll/sumAll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const sumAll = function() {

const sumAll = function(firstNum, lastNum) {
if (firstNum < 0 || lastNum < 0 || typeof firstNum !== "number" || typeof lastNum !== "number") {
return "ERROR";
}
let sum = 0;
const minNum = Math.min(firstNum, lastNum);
const maxNum = Math.max(firstNum, lastNum);
for (let i = minNum; i <= maxNum; i++) {
sum += i;
}
return sum;
};

// 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');
});
});
8 changes: 6 additions & 2 deletions 06_leapYears/leapYears.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const leapYears = function() {

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

// Do not edit below this line
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);
});
});
6 changes: 4 additions & 2 deletions 07_tempConversion/tempConversion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const convertToCelsius = function() {
const convertToCelsius = function(fTemp) {
return Math.round(((fTemp - 32) * 5/9) * 10) / 10;
};

const convertToFahrenheit = function() {
const convertToFahrenheit = function(cTemp) {
return Math.round(((cTemp * 9/5) + 32) * 10) / 10;
};

// 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);
});
});
28 changes: 16 additions & 12 deletions 08_calculator/calculator.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
const add = function() {

const add = function(num1, num2) {
return num1 + num2;
};

const subtract = function() {

const subtract = function(num1, num2) {
return num1 - num2;
};

const sum = function() {

const sum = function(nums) {
return nums.reduce((acc, value) => acc + value, 0);
};

const multiply = function() {

const multiply = function(nums) {
return nums.reduce((acc, value) => acc * value, 1);
};

const power = function() {

const power = function(num1, num2) {
return num1 ** num2;
};

const factorial = function() {

const factorial = function(num) {
let result = 1;
for (let i = num; i >= 2; i--) {
result *= i;
}
return result;
};

// Do not edit below this line
28 changes: 14 additions & 14 deletions 08_calculator/calculator.spec.js
Original file line number Diff line number Diff line change
@@ -5,17 +5,17 @@ describe('add', () => {
expect(calculator.add(0, 0)).toBe(0);
});

test.skip('adds 2 and 2', () => {
test('adds 2 and 2', () => {
expect(calculator.add(2, 2)).toBe(4);
});

test.skip('adds positive numbers', () => {
test('adds positive numbers', () => {
expect(calculator.add(2, 6)).toBe(8);
});
});

describe('subtract', () => {
test.skip('subtracts numbers', () => {
test('subtracts numbers', () => {
expect(calculator.subtract(10, 4)).toBe(6);
});
});
@@ -25,53 +25,53 @@ describe('sum', () => {
expect(calculator.sum([])).toBe(0);
});

test.skip('computes the sum of an array of one number', () => {
test('computes the sum of an array of one number', () => {
expect(calculator.sum([7])).toBe(7);
});

test.skip('computes the sum of an array of two numbers', () => {
test('computes the sum of an array of two numbers', () => {
expect(calculator.sum([7, 11])).toBe(18);
});

test.skip('computes the sum of an array of many numbers', () => {
test('computes the sum of an array of many numbers', () => {
expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25);
});
});

describe('multiply', () => {
test.skip('multiplies two numbers', () => {
test('multiplies two numbers', () => {
expect(calculator.multiply([2, 4])).toBe(8);
});

test.skip('multiplies several numbers', () => {
test('multiplies several numbers', () => {
expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120);
});
});

describe('power', () => {
test.skip('raises one number to the power of another number', () => {
test('raises one number to the power of another number', () => {
expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64
});
});

describe('factorial', () => {
test.skip('computes the factorial of 0', () => {
test('computes the factorial of 0', () => {
expect(calculator.factorial(0)).toBe(1); // 0! = 1
});

test.skip('computes the factorial of 1', () => {
test('computes the factorial of 1', () => {
expect(calculator.factorial(1)).toBe(1);
});

test.skip('computes the factorial of 2', () => {
test('computes the factorial of 2', () => {
expect(calculator.factorial(2)).toBe(2);
});

test.skip('computes the factorial of 5', () => {
test('computes the factorial of 5', () => {
expect(calculator.factorial(5)).toBe(120);
});

test.skip('computes the factorial of 10', () => {
test('computes the factorial of 10', () => {
expect(calculator.factorial(10)).toBe(3628800);
});
});
Loading