Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
968cd6c
inital pirate files
john-ko29 Aug 12, 2020
a23c2fb
accumlate product complete
john-ko29 Aug 16, 2020
e1ccc68
algrebra sequence exercise complete
john-ko29 Aug 17, 2020
30bfe6c
all about string exercise complete
john-ko29 Aug 18, 2020
eb1c462
alternating cap ex complete
john-ko29 Aug 19, 2020
96c2a39
alternate zero and ones complete
john-ko29 Aug 20, 2020
3a2f6b5
alliteration complete
john-ko29 Aug 21, 2020
f62ba67
are letters in second string present in first complete
john-ko29 Aug 22, 2020
16aad27
atm exercise done
john-ko29 Aug 23, 2020
f366c7d
automorphic number complete
john-ko29 Aug 24, 2020
e46ecc5
barbecue challenge complete
john-ko29 Aug 25, 2020
d683341
basic email validation complete
john-ko29 Aug 26, 2020
78d33ba
bird names abbrev complete
john-ko29 Aug 27, 2020
2fa375b
blackjack exercise complete
john-ko29 Aug 28, 2020
419f236
box exercise complete
john-ko29 Aug 29, 2020
84b0666
calculate the difference complete
john-ko29 Aug 30, 2020
517311f
calculate distance complete
john-ko29 Aug 31, 2020
c362b8b
capitalize first letter complete
john-ko29 Sep 1, 2020
650e360
capitalize name complete
john-ko29 Sep 2, 2020
a0b6a3d
anagram challenge complete
john-ko29 Sep 3, 2020
fa91b79
check prime number complete
john-ko29 Sep 4, 2020
f78a87a
check array done
john-ko29 Sep 5, 2020
f4b5aa5
inital files for palindrome
john-ko29 Sep 6, 2020
a6068a6
check palindrome complete
john-ko29 Sep 7, 2020
8b650cd
chocolate excercise complete
john-ko29 Sep 8, 2020
4912be6
attempted tree
john-ko29 Sep 9, 2020
a0919d7
attempted tree
john-ko29 Sep 10, 2020
4cbcd41
attempted tree
john-ko29 Sep 11, 2020
e720436
Compoundiing letters
john-ko29 Sep 12, 2020
d39f6e1
convenience complete
john-ko29 Sep 13, 2020
5b85ad3
convert key values to array
john-ko29 Sep 14, 2020
baa898b
convert number complete
john-ko29 Sep 15, 2020
82f8c90
count letter
john-ko29 Sep 16, 2020
a9977e1
count one binary
john-ko29 Sep 17, 2020
3d605f1
count letters and digits
john-ko29 Sep 18, 2020
4066e76
count dup complete
john-ko29 Sep 19, 2020
d765434
count char in string
john-ko29 Nov 1, 2020
eda86f5
counted ones complete
john-ko29 Nov 2, 2020
0eafbe0
even or odd complete
john-ko29 Nov 3, 2020
2dddfa5
factor chain complete
john-ko29 Nov 4, 2020
a64ec7a
filter out string complete
john-ko29 Nov 5, 2020
5ee02f9
find largest complete
john-ko29 Nov 6, 2020
9c2dca9
find the min max average
john-ko29 Nov 7, 2020
ce36426
find min and max complete
john-ko29 Nov 8, 2020
9856dd6
finding repeat
john-ko29 Mar 18, 2021
7545e33
finding repeat
john-ko29 Mar 19, 2021
4445dbc
shared letter
john-ko29 Mar 20, 2021
c3ec006
shared letter
john-ko29 Mar 21, 2021
363b73a
find the shortest
john-ko29 Mar 22, 2021
70a7794
find the shortest
john-ko29 Mar 23, 2021
ea37aab
flip array
john-ko29 Mar 24, 2021
52f06da
flip array
john-ko29 Mar 25, 2021
d829506
flip array
john-ko29 Mar 26, 2021
4c1b317
flip array
john-ko29 Mar 27, 2021
3c31cfb
flip array
john-ko29 Mar 28, 2021
fac6a97
flip array
john-ko29 Mar 29, 2021
38ab2b2
fridge poetry
john-ko29 Mar 30, 2021
c9d4fc0
fridge poetry
john-ko29 Mar 31, 2021
d5672ae
game of throne name
john-ko29 Apr 1, 2021
ffdecb3
game of throne name
john-ko29 Apr 2, 2021
7e6d0f3
gold distribution
john-ko29 Apr 3, 2021
8c030ff
gold distribution
john-ko29 Apr 4, 2021
c35d128
grocery
john-ko29 Apr 5, 2021
107761b
grocery
john-ko29 Apr 6, 2021
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
8 changes: 7 additions & 1 deletion easy/count-instances-of-a-character-in-a-string/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function charCount(myChar, str) {
// Your code here.
let counted = 0;
for (let i = 0; i < str.length; i++) {
if (str[i] === myChar) {
counted++;
}
}
return counted;
}

module.exports = charCount;
10 changes: 9 additions & 1 deletion easy/count-ones-in-a-2d-array/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
function countOnes(matrix) {
// Your code here.
let counted = 0;
for (let i = 0; i < matrix.length; i++) {
for (let k = 0; k < matrix[i].length; k++) {
if (matrix[i][k] === 1) {
counted++
}
}
}
return counted;
}

module.exports = countOnes;
6 changes: 5 additions & 1 deletion easy/even-or-odd-number-of-factors/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
function factorGroup(num) {
// Your code here.
if (num % 2 === 0) {
return "odd";
} else {
return "even";
}
}

module.exports = factorGroup;
7 changes: 6 additions & 1 deletion easy/factor-chain/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function factorChain(arr) {
// Your code here.
for (let i = 0; i < arr.length - 1; i++) {
if (arr[i + 1] % arr[i] !== 0) {
return false;
}
}
return true;
}

module.exports = factorChain;
8 changes: 7 additions & 1 deletion easy/filter-out-strings-from-an-array/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function filterArray(arr) {
// Your code here.
const newArr = [];
for (let i = 0; i < arr.length; i++) {
if (typeof(arr[i]) === "number") {
newArr.push(arr[i])
}
}
return newArr;
}

module.exports = filterArray;
12 changes: 11 additions & 1 deletion easy/find-the-largest-numbers-in-a-group-of-arrays/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
function findLargestNums(arr) {
// Your code here.
const newArr = [];
for (let i = 0; i < arr.length; i++) {
let biggest = arr[i][0]
for (let k = 0; k < arr[i].length; k++) {
if (arr[i][k] > biggest) {
biggest = arr[i][k]
}
}
newArr.push(biggest);
}
return newArr;
}

module.exports = findLargestNums;
20 changes: 19 additions & 1 deletion easy/find-the-minimum-maximum-length-and-average-values/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
function minMaxLengthAverage(arr) {
// Your code here.
const newArr = [];
let min = arr[0];
let max = arr[0];
let total = 0;
for (let i = 0; i < arr.length; i++) {
if (min > arr[i]) {
min = arr[i]
}
if (max < arr[i]) {
max = arr[i]
}
total += arr[i]
}
newArr.push(min);
newArr.push(max);
newArr.push(arr.length);
newArr.push(total / arr.length);

return newArr;
}

module.exports = minMaxLengthAverage;
16 changes: 15 additions & 1 deletion easy/find-the-smallest-and-biggest-numbers/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
function minMax(arr) {
// Your code here.
const newArr = [];
let min = arr[0];
let max = arr[0];
for (let i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i]
}
}
newArr.push(min);
newArr.push(max);

return newArr;
}

module.exports = minMax;
12 changes: 11 additions & 1 deletion hard/find-repeating/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
function findRepeating(str) {
// Your code here.
const arr = [];
let stack = 0;
const tempArr = [];
for (let i = 0; i < str.length; i++) {
let current = str[i];
if (stack === 0) {
tempArr.push(str[i]);
}
}

return arr;
}

module.exports = findRepeating;
13 changes: 12 additions & 1 deletion hard/find-the-shared-letters-between-two-strings/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
function sharedLetters(str1, str2) {
// Your code here.
const copies = [];
str1 = str1.toLowerCase();
str2 = str2.toLowerCase();
for (let i = 0; i < str1.length; i++) {
if (str2.includes(str1[i]) && !copies.includes(str1[i])) {
copies.push(str1[i]);
}
}

copies.sort();

return copies.join("");
}

module.exports = sharedLetters;
18 changes: 17 additions & 1 deletion hard/find-the-shortest-word-s-in-a-sentence/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
function findShortestWords(str) {
// Your code here.
const words = str.split(" ");
const wordLength = [];
const shortest = [];
let min = words[0].length;
for (let i = 0; i < words.length; i++) {
wordLength.push(words[i].length);
if (min > words[i].length) min = words[i].length;
}

for (let i = 0; i < words.length; i++) {
if (words[i].length === min && isNaN(parseInt(words[i]))) {
shortest.push(words[i].toLowerCase());
}
}

console.log(words, wordLength, min);
return shortest.sort();
}

module.exports = findShortestWords;
18 changes: 17 additions & 1 deletion hard/flip-the-array/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
function flipArray(arr) {
// Your code here.
if (!arr[0]) {
return [];
}
const newArr = [];
let columns = arr[0].length;

if (columns === undefined) {
for (let i = 0; i < arr.length; i++) {
newArr.push([arr[i]]);
}
} else {
for (let i = 0; i < arr.length; i++) {
newArr.push(arr[i][0]);
}
}

return newArr;
}

module.exports = flipArray;
11 changes: 10 additions & 1 deletion hard/fridge-poetry/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
function canBuild(s1, s2) {
// Your code here.
const string1 = s1.replace(/ /g, '');
const string2 = s2.replace(/ /g, '');

for (let i = 0; i < s1.length; i++) {
if (!s1.includes(s2[i])) {
return false;
}
}

return true;
}

module.exports = canBuild;
12 changes: 11 additions & 1 deletion hard/game-of-thrones-character-titles/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
function correctTitle(str) {
// Your code here.
const words = str.split(" ")
for (let i = 0; i < words.length; i++) {
const currentWord = words[i].toLowerCase();
if (currentWord === "and" || currentWord === "the" || currentWord === "of"
|| currentWord === "in") {
words[i] = currentWord;
} else {
words[i] = currentWord[0].toUpperCase() + currentWord.substring(1, currentWord.length);
}
}
return words.join(" ")
}

module.exports = correctTitle;
13 changes: 12 additions & 1 deletion hard/gold-distribution/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
function piratesKilled(gold, tolerance) {
// Your code here.
let max = 0;
for (let i = 0; i < gold.length; i++) {
if (max < gold[i]) {
max = gold[i]
}
}
for (let i = 0; i < gold.length; i++) {
if (tolerance[i] < (max - gold[i])) {
return true;
}
}
return false;
}

module.exports = piratesKilled;
8 changes: 7 additions & 1 deletion hard/grocery-store-prices/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function getPrices(arr) {
// Your code here.
const prices = [];
for (let i = 0; i < arr.length; i++) {
prices.push(arr[i].match(/\(([^)]+)\)/)[1])
prices[i] = parseFloat(prices[i].substr(1));
}

return prices;
}

module.exports = getPrices;
14 changes: 13 additions & 1 deletion medium/a-pirate-s-tale/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
function numberOfDays(coordinate) {
// Your code here.
let days = 0;
let daysTaken = 0;
for (let i = 0; i < coordinate.length; i++) {
if (coordinate[i] !== 0) {
if (days === 5) {
days = 0;
continue;
}

days++
}
}
return daysTaken;
}

module.exports = numberOfDays;
8 changes: 7 additions & 1 deletion medium/accumulating-product/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function accumulatingProduct(arr) {
// Your code here.
let accumulate = 0;
const newArray = [];
for (let i = 0; i < arr.length; i++) {
accumulate *= arr[i];
newArray.push(accumulate);
}
return newArray;
}

module.exports = accumulatingProduct;
13 changes: 12 additions & 1 deletion medium/algebra-sequence-boxes/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
function boxSeq(step) {
// Your code here.
let currentNumber = 0;
if (step === 0) {
return currentNumber;
}
for(let i = 1; i <= step; i++) {
if (i % 2 === 1) {
currentNumber += 3
} else {
currentNumber -= 1;
}
}
return currentNumber;
}

module.exports = boxSeq;
29 changes: 28 additions & 1 deletion medium/all-about-strings/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
function allAboutStrings(str) {
// Your code here.
const arr = [];
const letters = [];
let repeat = false;
arr.push(str.length);
arr.push(str.substring(0, 1));
arr.push(str.substring(str.length - 1));
if(str.length % 2 === 1) {
arr.push(str.substr((str.length - 1) / 2, 1))
} else {
arr.push(str.substr(((str.length - 1) / 2), 2))
}

for (let i = 0; i < str.length; i++) {
if (letters.includes(str[i])) {
arr.push(`@ index ${i}`)
repeat = true;
break;
} else {
letters.push(str[i])
}
}

if (!repeat) {
arr.push("not found");
}

console.log(arr)
return arr;
}

module.exports = allAboutStrings;
11 changes: 10 additions & 1 deletion medium/alternating-caps/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
function alternatingCaps(str) {
// Your code here.
let word = ""
for (let i = 0; i < str.length; i++) {
const letter = str[i];
if (i % 2 === 0) {
word += letter.toUpperCase();
} else {
word += letter.toLowerCase();
}
}
return word;
}

module.exports = alternatingCaps;
16 changes: 15 additions & 1 deletion medium/alternating-ones-and-zeroes/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
function canAlternate(s) {
// Your code here.
let zeros = 0;
let ones = 0;
for (let i = 0; i < s.length; i++) {
if (s[i] === "0") {
zeros++;
} else {
ones++;
}
}
const difference = zeros - ones;
if (difference > 1 || difference < -1) {
return false;
} else {
return true;
}
}

module.exports = canAlternate;
Loading