-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
130 lines (130 loc) · 4.37 KB
/
index.js
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
"use strict";
// Copyright (c) 2023 author Shakhbozbek Usmonov Miracle Programmer
// Day 3 Condingbat Warmup 1
// ---------- Started -----------------
// makes10(9, 10) → true
// makes10(9, 9) → false
// makes10(1, 9) → true
function makes10(a, b) {
return a === 10 || b === 10 || a + b === 10;
}
// console.log(makes10(9, 10)); // true
// console.log(makes10(9, 9)); // false
// console.log(makes10(1, 9)); // true
// ------------------------------------
// nearHundred(93) → true
// nearHundred(90) → true
// nearHundred(89) → false
function nearHundred(n) {
return Math.abs(n - 100) <= 10 || Math.abs(n - 200) <= 10;
}
// console.log(nearHundred(93)); // true
// console.log(nearHundred(90)); // true
// console.log(nearHundred(89)); // false
// ------------------------------------
// posNeg(1, -1, false) → true
// posNeg(-1, 1, false) → true
// posNeg(-4, -5, true) → true
function posNeg(a, b, negative) {
return ((a < 0 && b > 0) ||
(a > 0 && b < 0 && !negative) ||
(a < 0 && b < 0 && negative));
}
// console.log(posNeg(1, -1, false)); // true
// console.log(posNeg(-1, 1, false)); // true
// console.log(posNeg(-4, -5, true)); // true
// ------------------------------------------
// notString("candy") → "not candy"
// notString("x") → "not x"
// notString("not bad") → "not bad"
function notString(str) {
return str.startsWith("not") ? str : "not " + str;
}
// console.log(notString("candy")); // not candy
// console.log(notString("x")); // not x
// console.log(notString("not bad")); // not bad
// ------------------------------------------
// missingChar("kitten", 1) → "ktten"
// missingChar("kitten", 0) → "itten"
// missingChar("kitten", 4) → "kittn"
function missingChar(str, n) {
return str.slice(0, n) + str.slice(n + 1);
}
// console.log(missingChar("kitten", 1)); // ktten
// console.log(missingChar("kitten", 0)); // itten
// console.log(missingChar("kitten", 4)); // kittn
// console.log(missingChar("kitten", 5)); // kitte
// ------------------------------------------
// frontBack("code") → "eodc"
// frontBack("a") → "a"
// frontBack("ab") → "ba"
function frontBack(str) {
return str.length > 1
? str.slice(-1) + str.slice(1, -1) + str.slice(0, 1)
: str;
}
// console.log(frontBack("code")); // eodc
// console.log(frontBack("a")); // a
// console.log(frontBack("ab")); // ba
// ------------------------------------------
// front3('JavaScript') → JavJavJav
// front3('Chocolate') → ChoChoCho
// front3('abc') → abcabcabc
function front3(str) {
return str.slice(0, 3).repeat(3);
}
// console.log(front3("JavaScript")); // JavJavJav
// console.log(front3("Chocolate")); // ChoChoCho
// console.log(front3("abc")); // abcabcabc
// ------------------------------------------
// backAround('cat') → tcatt
// backAround('Hello') → oHelloo
// backAround('a') → aaa
function backAround(str) {
return str.slice(-1) + str + str.slice(-1);
}
// console.log(backAround("cat")); // tcatt
// console.log(backAround("Hello")); // oHelloo
// console.log(backAround("a")); // aaa
// ------------------------------------------
// or35(3) → true
// or35(10) → true
// or35(8) → false
function or35(n) {
return n % 3 === 0 || n % 5 === 0;
}
// console.log(or35(3)); // true
// console.log(or35(10)); // true
// console.log(or35(8)); // false
// ------------------------------------------
// front22('kitten') → kikittenki
// front22('Ha') → HaHaHa
// front22('abc') → ababcab
function front22(str) {
return str.slice(0, 2) + str + str.slice(0, 2);
}
// console.log(front22("kitten")); // kikittenki
// console.log(front22("Ha")); // HaHaHa
// console.log(front22("abc")); // ababcab
// ------------------------------------------
// startHi('hi there') → true
// startHi('hi') → true
// startHi('hello hi') → false
function startHi(str) {
return str.startsWith("hi");
}
// console.log(startHi("hi there")); // true
// console.log(startHi("hi")); // true
// console.log(startHi("hello hi")); // false
// ------------------------------------------
// icyHot(120, -1) → true
// icyHot(-1, 120) → true
// icyHot(2, 120) → false
function icyHot(temp1, temp2) {
return (temp1 < 0 && temp2 > 100) || (temp1 > 100 && temp2 < 0);
}
// console.log(icyHot(120, -1)); // true
// console.log(icyHot(-1, 120)); // true
// console.log(icyHot(2, 120)); // false
// ------------ End ------------
//# sourceMappingURL=index.js.map