forked from ironhackbcn/lab-javascript-basic-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-algorithms.js
More file actions
67 lines (40 loc) · 1.72 KB
/
basic-algorithms.js
File metadata and controls
67 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Names and Input
var hacker1 = 'Peter Pan';
console.log("The Driver's name is " + hacker1);
var hacker2 = prompt ("What's the navigator's name?");
console.log("The navigator's name is " +hacker2);
//Conditionals
if (hacker1.length > hacker2.length){
console.log(`The Driver has the longest name, it has ${hacker1.length} characters`);
} else if (hacker1.length == hacker2.length){
console.log(`wow, you both got equally long names, ${hacker1.length} characters!!`);
} else {
console.log(`Yo, navigator got the longest name, it has ${hacker2.length} characters`);
}
var hacker1SingleChar = [];
for (i = 0; i < hacker1.length; i++){
hacker1SingleChar.push(hacker1.charAt(i));
}
var h1PrintSingleChar = hacker1SingleChar.join(" ");
console.log(h1PrintSingleChar.toUpperCase());
var hacker2Reverse = [];
for (j = hacker2.length; j > -1; j--){
hacker2Reverse.push(hacker2.charAt(j));
}
var hacker2ReversePrint = hacker2Reverse.join("");
console.log(hacker2ReversePrint);
var a = "a";
var b = "b";
if (a < b){
console.log(a);
}
/* Stuck here, tried something but haven't solved it. Was not clear to me if we can use all in built functions and methods in javascript. */
for (i = hacker1.indexOf(0); i <= hacker1.length; i++){
for (j = hacker2.indexOf(0); j <= hacker2.length; j++)
if (hacker1.charAt(i) < hacker2.charAt(j)){
console.log(`Hacker1 letter at position ${i} comes alphabet first. Letter is ${hacker1.charAt(i)}`);
console.log(`Hacker1 letter at position ${j} comes alphabet first. Letter is ${hacker2.charAt(j)}`);
} else if (hacker1.charAt(i) > hacker2.charAt(j)){
}
}
// Lorem ipsum generator