Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const helloWorld = function() {
return ''
return 'Hello, World!'
};

module.exports = helloWorld;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function numberChecker(number) {
if (number === 6) {
if (number >= 10) {
return true;
} else {
return false;
Expand Down
26 changes: 16 additions & 10 deletions foundations/object_basics/01_calculator/calculator.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
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) {
return arr.reduce((elem, total) => elem+total,0);

};

const multiply = function() {

const multiply = function(arr) {
return arr.reduce((elem, total) => elem*total,1);
};

const power = function() {

const power = function(base, exponent) {
return base ** exponent;
};

const factorial = function() {

const factorial = function(num) {
if(num === 0 || num === 1){
return 1;
}

return num * factorial(num-1);
};

// Do not edit below this line
Expand Down
22 changes: 21 additions & 1 deletion foundations/object_basics/02_palindromes/palindromes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
const palindromes = function () {
const palindromes = function (str) {
let l = 0;
let r = str.length-1;

const newStr = str.toLowerCase();

while (l < r){
while("!¡?¿.,-´ '".includes(newStr[l])){
l+=1;
}

while("!¡?¿.,-´ '".includes(newStr[r])){
r-=1;
}
if(newStr[l] !== newStr[r]){
return false;
}
l+=1;
r-=1;
}
return true;

};

Expand Down
8 changes: 7 additions & 1 deletion foundations/object_basics/03_fibonacci/fibonacci.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const fibonacci = function() {
const fibonacci = function(num) {
if(num === 1 || num === 2){
return 1;
}

return fibonacci(num-1) + fibonacci(num-2);

};


// Do not edit below this line
module.exports = fibonacci;
3 changes: 2 additions & 1 deletion foundations/object_basics/04_getTheTitles/getTheTitles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const getTheTitles = function() {
const getTheTitles = function(books) {
return books.map(book => book.title);

};

Expand Down
16 changes: 15 additions & 1 deletion foundations/object_basics/05_findTheOldest/findTheOldest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
const findTheOldest = function() {
const findTheOldest = function(arr) {
let oldest = 0;
let oldestName;

for(person of arr){
let deathYear = person.yearOfDeath ? person.yearOfDeath: 2025;
let age = deathYear - person.yearOfBirth;

if(age > oldest){
oldest = age;
oldestName = person;
}
}
return oldestName;

};


// Do not edit below this line
module.exports = findTheOldest;
Loading