-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-8-21.js
More file actions
143 lines (77 loc) · 3.29 KB
/
Copy path6-8-21.js
File metadata and controls
143 lines (77 loc) · 3.29 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Regex count lowercase letters
// Your task is simply to count the total number of lowercase letters in a string.
// Examples
// lowercaseCount("abc"); ===> 3
// lowercaseCount("abcABC123"); ===> 3
// lowercaseCount("abcABC123!@€£#$%^&*()_-+=}{[]|\':;?/>.<,~"); ===> 3
// lowercaseCount(""); ===> 0;
// lowercaseCount("ABC123!@€£#$%^&*()_-+=}{[]|\':;?/>.<,~"); ===> 0
// lowercaseCount("abcdefghijklmnopqrstuvwxyz"); ===> 26
function lowercaseCount(str){
//How many?
return (str.match(/[a-z]/g) == null) ? 0 : str.match(/[a-z]/g).length
}
// Swap Values
// I would like to be able to pass an array with two elements to my swapValues function to swap the values. However it appears that the values aren't changing.
// Can you figure out what's wrong here?
function swapValues(a) {
return a.reverse()
}
// Hex to Decimal
// Complete the function which converts hex number (given as a string) to a decimal number.
function hexToDec(hexString){
//your code here
return parseInt(hexString,16)
}
// Basic Training: Add item to an Array
// Add the value "codewars" to the websites array.
// After your code executes the websites array should == ["codewars"]
// The websites array has already been defined for you using the following code:
// var websites = [];
// add the value "codewars" to the already defined websites array
websites.push('codewars')
// Classic Hello World
// You are given a method called main, make it print the line Hello World! and don't return anything
// Note that for some languages, the function main is the entry point of the program.
// Here's how it will be tested:
// Print "Hello World!" to the screen
class Solution{
static main() {
console.log('Hello World!')
}
}
// Simple validation of a username with regex
// Write a simple regex to validate a username. Allowed characters are:
// lowercase letters,
// numbers,
// underscore
// Length should be between 4 and 16 characters (both included).
function validateUsr(username) {
return /^[a-z0-9_]{4,16}$/.test(username)
}
// validate code with simple regex
// Basic regex tasks. Write a function that takes in a numeric code of any length. The function should check if the code begins with 1, 2, or 3 and return true if so. Return false otherwise.
// You can assume the input will always be a number.
//FIRST TRYYYYY
function validateCode (code) {
//your code here
return /^[1-3]/.test(code)
}
// Duck Duck Goose
// The objective of Duck, duck, goose is to walk in a circle, tapping on each player's head until one is chosen.
// Task: Given an array of Player objects (an array of associative arrays in PHP) and an index (1-based), return the name of the chosen Player(name is a property of Player objects, e.g Player.name)
function duckDuckGoose(players, goose) {
// ...
return players[(goose-1)%players.length].name
}
// Wilson primes
// Wilson primes satisfy the following condition. Let P represent a prime number.
// Then ((P-1)! + 1) / (P * P) should give a whole number.
// Your task is to create a function that returns true if the given number is a Wilson prime.
function amIWilson(p) {
// check if prime is Wilson
function factorial(n) {
return (n != 1) ? n * factorial(n - 1) : 1;
}
return ((factorial(p-1)+1) / (p**2))%1==0
}