Skip to content

Commit 7322aef

Browse files
committed
Initial commit
0 parents  commit 7322aef

File tree

8 files changed

+210
-0
lines changed

8 files changed

+210
-0
lines changed

days.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Complete the function which returns the weekday according to the input number:
2+
3+
// 1 returns "Sunday"
4+
// 2 returns "Monday"
5+
// 3 returns "Tuesday"
6+
// 4 returns "Wednesday"
7+
// 5 returns "Thursday"
8+
// 6 returns "Friday"
9+
// 7 returns "Saturday"
10+
11+
// Otherwise returns "Wrong, please enter a number between 1 and 7"
12+
13+
whatday = num => {
14+
switch (num) {
15+
case 1: return 'Sunday';
16+
case 2: return 'Monday';
17+
case 3: return 'Tuesday';
18+
case 4: return 'Wednesday';
19+
case 5: return 'Thursday';
20+
case 6: return 'Friday';
21+
case 7: return 'Saturday';
22+
default: return 'Wrong, please enter a number between 1 and 7';
23+
}
24+
}
25+
26+
// *********************************************************
27+
28+
whatday = num => ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][num] || 'Wrong, please enter a number between 1 and 7'
29+
30+
console.log(whatday(2));

filter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const filter = [1,2,3,4].filter((num)=>{ return num > 3})
2+
3+
console.log(filter);

jadencase.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jaden Smith, the son of Will Smith, is the star of films such as The Karate Kid (2010) and After Earth (2013). Jaden is also known for some of his philosophy that he delivers via Twitter. When writing on Twitter, he is known for almost always capitalizing every word.
2+
3+
// Your task is to convert strings to how they would be written by Jaden Smith. The strings are actual quotes from Jaden Smith, but they are not capitalized in the same way he originally typed them.
4+
5+
// Example:
6+
7+
// Not Jaden-Cased: "How can mirrors be real if our eyes aren't real"
8+
// Jaden-Cased: "How Can Mirrors Be Real If Our Eyes Aren't Real"
9+
10+
String.prototype.toJadenCase = function() {
11+
return this.split(" ")
12+
.map(word => word[0].toUpperCase() + word.slice(1))
13+
.join(" ");
14+
};
15+
16+
const str = "How can mirrors be real if our eyes aren't real";
17+
18+
console.log(str.toJadenCase());

morsecode.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
$('#morse').on('keyup', function () {
2+
const value = $(this).val();
3+
const output = '';
4+
5+
if (value === '') {
6+
$('#text').text('');
7+
8+
return false;
9+
} // if (value === '')
10+
11+
for (const i = 0; i < value.length; i++) {
12+
output += converter[value.charAt(i).toLowerCase()];
13+
} // for (const i = 0; i < value.length; i++)
14+
15+
$('#text').text(output);
16+
});
17+
18+
const converter = {
19+
'a': '.-',
20+
'b': '-...',
21+
'c': '-.-.',
22+
'd': '-..',
23+
'e': '.',
24+
'f': '..-.',
25+
'g': '--.',
26+
'h': '....',
27+
'i': '..',
28+
'j': '.---',
29+
'k': '-.-',
30+
'l': '.-..',
31+
'm': '--',
32+
'n': '-.',
33+
'o': '---',
34+
'p': '.--.',
35+
'q': '--.-',
36+
'r': '.-.',
37+
's': '...',
38+
't': '-',
39+
'u': '..-',
40+
'v': '...-',
41+
'w': '.--',
42+
'x': '-..-',
43+
'y': '-.--',
44+
'z': '--..',
45+
'1': '.----',
46+
'2': '..---',
47+
'3': '...--',
48+
'4': '....-',
49+
'5': '.....',
50+
'6': '-....',
51+
'7': '--...',
52+
'8': '---..',
53+
'9': '----.',
54+
'0': '-----',
55+
'.': '.-.-.-',
56+
',': '--..--',
57+
'?': '..--..',
58+
"'": '.----.',
59+
'!': '-.-.--',
60+
'/': '-..-.',
61+
'(': '-.--.',
62+
')': '-.--.-',
63+
'&': '.-...',
64+
':': '---...',
65+
';': '-.-.-.',
66+
'=': '-...-',
67+
'+': '.-.-.',
68+
'-': '-....-',
69+
'_': '..--.-',
70+
'"': '.-..-.',
71+
'$': '...-..-',
72+
'@': '.--.-.',
73+
' ': ' '
74+
}

points.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the array.
2+
3+
// For example: ["3:1", "2:2", "0:1", ...]
4+
5+
// Write a function that takes such list and counts the points of our team in the championship. Rules for counting points for each match:
6+
7+
// if x>y - 3 points
8+
// if x<y - 0 point
9+
// if x=y - 1 point
10+
11+
function points(games) {
12+
let total = 0;
13+
games.map(game => {
14+
if (game[0] === game[2]) {
15+
total += 1;
16+
} else if (game[0] > game[2]) {
17+
total += 3;
18+
}
19+
});
20+
return total;
21+
}
22+
23+
// *********************************************************
24+
25+
function points(games) {
26+
return games.reduce((current, element) => {
27+
let arraySplit = element.split(':');
28+
return (arraySplit[0] > arraySplit[1]) ? current += 3 : (arraySplit[0] < arraySplit[1]) ? current : current += 1;
29+
}, 0);
30+
}
31+
32+
// *********************************************************
33+
34+
const points = games => games.reduce((sum, [x, , y]) => sum + (x > y ? 3 : x == y), 0)
35+
36+
const result = points(["3:1", "2:2", "0:1"])
37+
38+
console.log(result);

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# CodeWars
2+
3+
## About
4+
5+
This is a collection of JavaScript code challenges completed on codewars.com
6+
7+
## Purpose
8+
9+
The purpose of this repository is simply to document some of the fun and interesting things I've learned from these little exercises
10+
11+
## How to run
12+
13+
Make sure you have [Node.js](https://nodejs.org/en/download/) installed on your computer
14+
15+
Run each file in the terminal. E.G:
16+
17+
```javascript
18+
node days.js
19+
```

sheep.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Given a non-negative integer, 3 for example, return a string with a murmur: "1 sheep...2 sheep...3 sheep...". Input will always be valid, i.e. no negative integers.
2+
3+
var countSheep = function (num){
4+
let str = "";
5+
for(let i = 1; i <= num; i++) { str+= `${i} sheep...`; }
6+
return str;
7+
}
8+
9+
// *********************************************************
10+
11+
countSheep = num => [...Array(num).keys()].map(x=>`${x+1} sheep...`).join``
12+
13+
console.log(countSheep(3));

vowels.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Trolls are attacking your comment section!
2+
3+
// A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat.
4+
5+
// Your task is to write a function that takes a string and return a new string with all vowels removed.
6+
7+
// For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!".
8+
9+
// Note: for this kata y isn't considered a vowel.
10+
11+
function disemvowel(str) {
12+
return str.replace(/[aeiou]/gi, "");
13+
}
14+
15+
console.log(disemvowel("Hello, how are you?"));

0 commit comments

Comments
 (0)