Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lab 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>findPrimes(a, b)</title>
</head>
<script>
function findPrimes(min, max) {
var sieve = [], i, j, primes = [], ans = [];
for (i = 2; i <= max; ++i) {
if (!sieve[i]) {
// i has not been marked -- it is prime/
primes.push(i);
for (j = i << 1; j <= max; j += i) {
sieve[j] = true;
}
}
}
for (j = min; j <= max; ++j){
for (i = 0; i <= primes.length; ++i){
if (j == primes[i]){
ans.push(j);
}
}
}
return ans
}
a = prompt("1")
b = prompt("2")
c = Math.min(a, b)
d = Math.max(a, b)
a = c
b = d
delete c
delete d
console.log(findPrimes(a, b))
//alert(findPrimes(a, b))
/*var i = 0;
while (i != 10) {
i += 0.2;
}
x << y == x * 2 ** y
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
|| (ИЛИ),
&& (И) и
! (НЕ) (функции и значение).
^ (Побитовое XOR)Раздел
Производит побитовое XOR над каждой парой битов. Операция a XOR b вернет 1 если a и b различны.
~ (Побитовое NOT) Производит операцию NOT над каждым битом. NOT a вернет побитово инвертированное значение (обратный код) операнда.*/
</script>
<body>
<p>і просто не досягає 10, а просто "проскакує" це значення</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>isInteger(num)</title>
</head>
<script>
function isInteger(num) {
if (num == parseInt(num)){
return(true)}
return false;
}
alert( isInteger(1) ); // true
alert( isInteger(1.5) ); // false
alert( isInteger(-0.5) ); // false
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>findHexColor(text)</title>
</head>
<script>
function findHexColor(text) {
s1 = /(#)(([A-C]|[a-c]|[0-9])([A-C]|[a-c]|[0-9])([A-C]|[a-c]|[0-9])([A-C]|[a-c]|[0-9])([A-C]|[a-c]|[0-9])([A-C]|[a-c]|[0-9]))/g;
s2 = /#([A-C]|[a-c]|[0-9])([A-C]|[a-c]|[0-9])([A-C]|[a-c]|[0-9])/g;
return (text.match(s1) || text.match(s2));
}
var x = prompt("Input string to chec:")
alert(findHexColor(x))
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Завдання findRGBAColor(text)</title>
</head>
<script>
function findRGBAColor(text) {
j = 0
//change ( and ) to ' and " like mystring.replace(/\./g,' ')
while (j < text.length){
if ((text[j]) == "r"){
//return j + 1 //to test
s = text.indexOf(")", j) + 1
/*text = text.replace(/\(/g,"'")
text = text.replace(/\)/g,'"')*/
if (/^(rgba)(\()(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\, (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\, (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\, (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\))$/.test(text.slice(j, s))) {
/*text = text.replace(/\'/g,"(")
text = text.replace(/\"/g,")")*/
return text.slice(j, s)
}
else{
/*text = text.replace(/\'/g,"(")
text = text.replace(/\"/g,")")*/
j += 1
}
}
else{
j += 1
}
}
return null
/*if (/^(rgba)(')(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\, (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\, (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\, (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(")$/.test(text)) {
return (true)
}
return (false)*/
}
/*
\ - показує, що це спецсимвол, який має бути у якості елемента рядка, а не коду.
rgba(12, 14, 15, 14)
function isIPAddress(ip) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip)) {
return (true)
}
// alert("You have entered an invalid IP address!")
return (false)
}
rgba(r, g, b, a) 0<r<255*/
var x = prompt("Input string to chec:")
alert(findRGBAColor(x))
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Завдання isIPAddress(ip)</title>
</head>
<script>
function isIPAddress(ip) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip)) {
return (true)
}
// alert("You have entered an invalid IP address!")
return (false)
}
var x = prompt("Input string to chec:")
alert(isIPAddress(x))
</script>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment