Skip to content

Commit 9027589

Browse files
committed
algorithms part one
0 parents  commit 9027589

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

Diff for: FIBO.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//This algorithm at the start as parametr takes the number of items, which recursion will execute.
2+
//The variable ${startNum} specifies the first two starting numbers.
3+
4+
const fibonacciMax = (max) =>{
5+
let startNum = [0, 1];
6+
for(let i=startNum[1]; i<max; i++){
7+
let nextNum = startNum[i]+startNum[i-1];
8+
startNum.push(nextNum);
9+
}
10+
console.log(startNum.join(", "));
11+
}
12+
13+
//Enter the number of items as argument.
14+
fibonacciMax(10);

Diff for: FIZZBUZZ.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//The following algorithms is to test that your input is number or string...
2+
//If this is number, checks if a number is double by 3, 5 or either way. If string - return string.
3+
//What will happen if your input is nothing?
4+
5+
const funFunction = (num) =>{
6+
let f = "FIZZ";
7+
let b = "BUZZ";
8+
9+
for(let i=0; i<num && !isNaN(num); i++){
10+
if(num%15 === 0){
11+
return f+b; //FIZZBUZZ
12+
}else if(num%3 === 0){
13+
return f; // FIZZ
14+
}else if(num%5 === 0){
15+
return b; // BUZZ
16+
}else{
17+
return `no ${f}.. no ${b}..` // no FIZZ.. no BUZZ..
18+
};
19+
};
20+
21+
// this part checks num as contents, if nothing - return information
22+
for(let i=num; i===undefined; i++){
23+
return `enter your number`;
24+
};
25+
26+
for(let i=num; isNaN(i); i++){
27+
return `this is string, input number...`;
28+
};
29+
30+
};
31+
32+
// START CHECKING
33+
let checkItOut = funFunction(/*ENTER YOUR NUMBER*/);
34+
console.log(`${checkItOut}`);

Diff for: HOW_MANY.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//This function will check which character is the most.
2+
const myFun = (input) => {
3+
let obj = {};
4+
5+
for(const element of input){
6+
obj[element] = obj[element] + 1 || 1;
7+
};
8+
9+
const x = Object.entries(obj).map(e => e.reverse()).sort().reverse();
10+
11+
console.log(`The letter ${x[0][1]} are the most numerous, there are ${x[0][0]} of them`);
12+
}
13+
14+
//Enter a string as an argument:
15+
myFun(`asfgrgsggtssg`);

Diff for: PALINDROME.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//The main advantage of this algorithm is that it checks the string to half, which contributes to less memory loss.
2+
3+
const isPalindrome = (words) =>{
4+
const lng = words.length;
5+
for(let i=0; i<lng/2; i++){
6+
if(words[i] === words[lng-1-i]){
7+
return true;
8+
}else{
9+
return false;
10+
}
11+
}
12+
};
13+
14+
//Enter argument(e.g. civic, refer, level) or else word.
15+
let yourPalindrome = isPalindrome('RACECAR');
16+
console.log(`${yourPalindrome}`);

Diff for: firstLetterBig.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//This alghoritm change all words, which you will pass.
2+
//Take a moment to review this code...
3+
//I used RegExp for the capture what is to be taken into account.
4+
5+
const changeSign = (words) =>{
6+
7+
const complete = [];
8+
9+
for(let i=1; i<=words.split(" ").length; i++){
10+
let regex = /[^a-zA-Z\s]/g;
11+
let items = words.replace(regex, '').split(" ");
12+
let changeItems = items[i-1].slice(0, 1).toUpperCase() + items[i-1].toLowerCase().slice(1);
13+
14+
complete.push(changeItems);
15+
}
16+
console.log(complete.join(' '));
17+
}
18+
19+
// enter your sign here:
20+
changeSign(`▷wElcoME t@o my ALGHOriTm!𝄞`);

Diff for: readMe.pdf

151 KB
Binary file not shown.

0 commit comments

Comments
 (0)