Skip to content

Commit 9a618f6

Browse files
committed
added pancake
1 parent 129cfac commit 9a618f6

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

.DS_Store

-2 KB
Binary file not shown.

pancakeSort.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// pancake sort
2+
3+
function panCake(arr) {
4+
for (let i = arr.length - 1; i > 0; i--) {
5+
let pivot = maxIndex(arr, i);
6+
console.log(pivot);
7+
flip(arr, pivot);
8+
flip(arr, i);
9+
}
10+
return arr;
11+
}
12+
13+
function flip(arr, k) {
14+
for (let i = 0; i < Math.floor(k + 1 / 2); i++) {
15+
let tmp = arr[i];
16+
arr[i] = arr[k - i];
17+
arr[k - i] = tmp;
18+
}
19+
}
20+
21+
function maxIndex(arr, k) {
22+
let index = 0;
23+
for (let i = 0; i <= k; i++) {
24+
if (arr[index] < arr[i]) {
25+
index = i;
26+
}
27+
}
28+
return index;
29+
}
30+
31+
console.log(panCake([4, 5, 3, 6, 2, 1]));
32+
// arr=[5,3,4,2,1]
33+
//

script.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
git add .
3+
read -p "Commit description: " desc
4+
git commit -m "$desc"
5+
git push origin master

wordsToNumbers.js

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,22 @@ var Small = {
3131

3232
var Magnitude = {
3333
thousand: 1000,
34-
million: 1000000,
35-
billion: 1000000000,
36-
trillion: 1000000000000,
37-
quadrillion: 1000000000000000,
38-
quintillion: 1000000000000000000,
39-
sextillion: 1000000000000000000000,
40-
septillion: 1000000000000000000000000,
41-
octillion: 1000000000000000000000000000,
42-
nonillion: 1000000000000000000000000000000,
43-
decillion: 1000000000000000000000000000000000
34+
hundred: 100
4435
};
4536

46-
var a, n, g;
47-
4837
function text2num(s) {
49-
a = s.toString().split(/[\s-]+/);
50-
n = 0;
51-
g = 0;
52-
a.forEach(feach);
53-
return n + g;
54-
}
55-
56-
function feach(w) {
57-
var x = Small[w];
58-
if (x != null) {
59-
g = g + x;
60-
} else if (w == "hundred") {
61-
g = g * 100;
62-
} else {
63-
x = Magnitude[w];
64-
if (x != null) {
65-
n = n + g * x;
66-
g = 0;
67-
} else {
68-
alert("Unknown number: " + w);
38+
let arr = s.split(" ");
39+
let num = [];
40+
for (let i = 0; i < arr.length; i++) {
41+
if (arr[i] in Small) {
42+
let val = arr[i];
43+
num.push(Small[val]);
44+
}
45+
if (arr[i] in Magnitude) {
46+
num[num.length - 1] = num[num.length - 1] * Magnitude[arr[i]];
6947
}
7048
}
49+
console.log(num);
7150
}
51+
52+
text2num("one thousand two hundred twenty two");

0 commit comments

Comments
 (0)