diff --git a/README.md b/README.md index 4a870ccfed..f0e90fc8d3 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,8 @@ npm test -- 'playground' ### References -[▶ Data Structures and Algorithms on YouTube](https://www.youtube.com/playlist?list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8) +- [▶ Data Structures and Algorithms on YouTube](https://www.youtube.com/playlist?list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8) +- [✍🏻 Data Structure Sketches](https://okso.app/showcase/data-structures) ### Big O Notation diff --git a/src/algorithms/math/factors/README.md b/src/algorithms/math/factors/README.md new file mode 100644 index 0000000000..91046e2078 --- /dev/null +++ b/src/algorithms/math/factors/README.md @@ -0,0 +1,21 @@ +# factor + + +What is factor? + +Factor is a term in multiplication for a whole number by which a larger whole number can be divided. +A factor is a number that divides another number, leaving no remainder. +a factor is a number that divides another number without leaving any remainder. +In contrast, a multiple is a number that, when divided a certain of times by another number, no remainder is left. +To be the factors of a number, the factor number should exactly divide the number (with 0 remainder). +There are two methods of finding factors: multiplication and division. +In addition, rules of divisibility may also be used. + + +## References + +https://en.wikipedia.org/wiki/Factor#Mathematics + +https://www.storyofmathematics.com/factors-multiples/ + +https://www.splashlearn.com/math-vocabulary/multiplication/factor diff --git a/src/algorithms/math/factors/_test_/factors.test.js b/src/algorithms/math/factors/_test_/factors.test.js new file mode 100644 index 0000000000..ad13c683ee --- /dev/null +++ b/src/algorithms/math/factors/_test_/factors.test.js @@ -0,0 +1,15 @@ +import { factors } from '../factors'; + +describe('factors', () => { + it('should find factors', () => { + expect(factors(1)).toEqual([1]); + expect(factors(2)).toEqual([1, 2]); + expect(factors(3)).toEqual([1, 3]); + expect(factors(4)).toEqual([1, 2, 4]); + expect(factors(5)).toEqual([1, 5]); + expect(factors(14)).toEqual([1, 2, 7, 14]); + expect(factors(40)).toEqual([1, 2, 4, 5, 8, 10, 20, 40]); + expect(factors(54)).toEqual([1, 2, 3, 6, 9, 18, 27, 54]); + expect(factors(100)).toEqual([1, 2, 4, 5, 10, 20, 25, 50, 100]); + }); +}); diff --git a/src/algorithms/math/factors/factors.js b/src/algorithms/math/factors/factors.js new file mode 100644 index 0000000000..22d324a56a --- /dev/null +++ b/src/algorithms/math/factors/factors.js @@ -0,0 +1,16 @@ +/** + * Finds the factor of a number. + */ +export default function printFactors(x) { + console.log('The factors of', x, 'are:'); + // looping + for (let i = 1; i <= x; i++) { + if (x % i === 0) { + console.log(i); + } + } +} + +// get the input from the user +const num = prompt('Enter a positive integer: '); +printFactors(num); diff --git a/src/data-structures/heap/images/array-representation.jpeg b/src/data-structures/heap/images/array-representation.jpeg index 0a757d7ac0..8914e7102e 100644 Binary files a/src/data-structures/heap/images/array-representation.jpeg and b/src/data-structures/heap/images/array-representation.jpeg differ diff --git a/src/data-structures/heap/images/max-heap.jpeg b/src/data-structures/heap/images/max-heap.jpeg index c818c07f06..c1585d0302 100644 Binary files a/src/data-structures/heap/images/max-heap.jpeg and b/src/data-structures/heap/images/max-heap.jpeg differ diff --git a/src/data-structures/heap/images/min-heap.jpeg b/src/data-structures/heap/images/min-heap.jpeg index 48526d6cdc..646923b2df 100644 Binary files a/src/data-structures/heap/images/min-heap.jpeg and b/src/data-structures/heap/images/min-heap.jpeg differ diff --git a/src/data-structures/queue/images/queue.jpeg b/src/data-structures/queue/images/queue.jpeg index 0e412d550a..579f4d8c83 100644 Binary files a/src/data-structures/queue/images/queue.jpeg and b/src/data-structures/queue/images/queue.jpeg differ diff --git a/src/data-structures/stack/images/stack.jpg b/src/data-structures/stack/images/stack.jpg new file mode 100644 index 0000000000..8c966f276f Binary files /dev/null and b/src/data-structures/stack/images/stack.jpg differ diff --git a/src/data-structures/tree/binary-search-tree/images/binary-search-tree.jpg b/src/data-structures/tree/binary-search-tree/images/binary-search-tree.jpg index f85341d53c..1309e4ee4d 100644 Binary files a/src/data-structures/tree/binary-search-tree/images/binary-search-tree.jpg and b/src/data-structures/tree/binary-search-tree/images/binary-search-tree.jpg differ diff --git a/src/data-structures/tree/images/tree.jpeg b/src/data-structures/tree/images/tree.jpeg index d591972560..c888843d6c 100644 Binary files a/src/data-structures/tree/images/tree.jpeg and b/src/data-structures/tree/images/tree.jpeg differ diff --git a/src/data-structures/trie/images/trie.jpg b/src/data-structures/trie/images/trie.jpg index 8e160b1e8a..001b04f2e7 100644 Binary files a/src/data-structures/trie/images/trie.jpg and b/src/data-structures/trie/images/trie.jpg differ