-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6kyu6.js
More file actions
106 lines (86 loc) · 3.38 KB
/
Copy path6kyu6.js
File metadata and controls
106 lines (86 loc) · 3.38 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
/* You will be given an array of objects representing data about developers who have signed up to attend the next web development meetup that you are organising.
Three programming languages will be represented: Python, Ruby and JavaScript.
Your task is to return either:
true if the number of meetup participants representing any of the three programming languages is ** at most 2 times higher than the number of developers representing any of the remaining programming languages**; or
false otherwise.*/
function isLanguageDiverse(list) {
let pcounter = 0;
let rcounter = 0;
let jcounter = 0;
for(let i = 0; i < list.length; i += 1){
if(list[i].language.toLowerCase() === 'python'){
pcounter += 1;
}
else if(list[i].language.toLowerCase() === 'ruby'){
rcounter += 1;
}
else{
jcounter += 1;
}
}
let max = Math.max(pcounter, rcounter, jcounter);
if(max/pcounter <= 2 && max/rcounter <= 2 && max/jcounter <= 2) return true;
else {
return false;
}
}
/*A stream of data is received and needs to be reversed.
Each segment is 8 bits long, meaning the order of these segments needs to be reversed
The total number of bits will always be a multiple of 8.
The data is given in an array*/
function dataReverse(data) {
let result = [];
while(data.length != 0){
let byte = data.splice(0, 8);
result.unshift(byte);
}
return result.flat();
}
/* An ATM ran out of 10 dollar bills and only has 100, 50 and 20 dollar bills.Given an amount between 40 and 10000 dollars (inclusive) and assuming that the ATM
wants to use as few bills as possible, determinate the minimal number of 100, 50 and 20 dollar bills the ATM needs to dispense (in that order).*/
function withdraw(n) {
for(let i = 0; i <= 100; ++i){
for(let j = 0; j <= 100; ++j){
for(let k = 0; k <= 100; ++k){
if(k*100 + j*50 + i*20 === n) return [k, j, i];
}
}
}
}
/*Given a list and a number, create a new list that contains each number of list at most N times, without reordering.
For example if the input number is 2, and the input list is [1,2,3,1,2,1,2,3], you take [1,2,3,1,2],
drop the next [1,2] since this would lead to 1 and 2 being in the result 3 times, and then take 3, which leads to [1,2,3,1,2,3].
With list [20,37,20,21] and number 1, the result would be [20,37,21]. */
function deleteNth(arr,n){
let newArr = [];
let result = {};
newArr = arr.map(function(a){
if (result[a] < n && result[a] > 0){
result[a] += 1;
return a;
}
else if(result[a] === undefined){
result[a] = 1;
return a;
}
else {
result[a] += 1;
}
});
return newArr.filter((elem) => elem != undefined);
}
/* Your task is to write a function which cuts cancer cells from the body.
Cancer cells are divided into two types:
Advance stage,described as letter C
Initial stage,described as letter c
Rest cells are divided as follows:
Normal cell,described as lowercase letter
Important cell,described as uppercase letter
Prerequisites:
Important cell,cannot be cut out.
Advance cancer cell,should be cut out with adjacent cells if it can be done.
Function input is a string (representing a body), remove "cancer" characters (based on the described rules)
and return the body cured of those "cancer" characters.*/
function cutCancerCells(organism){
return organism.replace(/c|[a-z]?C[a-z]?/g, '');
}