Skip to content

Instantly share code, notes, and snippets.

View code-reaper08's full-sized avatar
🔄
To iterate is human, to recurse divine.

Vishwa R code-reaper08

🔄
To iterate is human, to recurse divine.
View GitHub Profile
@code-reaper08
code-reaper08 / Sieve.html
Created July 20, 2021 19:22
Sieve of Eratosthenes
<!DOCTYPE html>
<html>
<body>
<h3>Click the button to execute Seive of Eratosthenes</h3>
<div id="buttondiv">
<button id="Button" onclick="FindPrime()">Give a number</button>
</div>
@code-reaper08
code-reaper08 / Sieve.js
Created July 20, 2021 19:25
Seive of Eratosthenes
let Boolarray = [];
let n = 100;
for (var i = 0; i < n; i++) {
Boolarray.push(true);
}
for (let j = 2; j * j <= n; j++) {
if (Boolarray[j] == true) {
for (let k = 2 * j; k <= n; k += j) {
Boolarray[k] = false;
}
@code-reaper08
code-reaper08 / string.js
Created July 24, 2021 16:15
String example
// sample string in JS
let sample_string = "Hello readers";
@code-reaper08
code-reaper08 / Substring.js
Created July 24, 2021 16:22
Substring example
// sample string
let sample_string = "wsad";
// substrings of the above string
w
ws
wsa
wsad
s
sa
sad
// Initialising input string
let inpstring = "Hello";
// length of the input string
let n = inpstring.length;
@code-reaper08
code-reaper08 / Function.js
Created July 24, 2021 17:18
Creating function
let inpstring = "abc";
let n = inpstring.length;
function FindSubstring(Str, n){
for(let i=0; i<n ;i++){
// We are going to have two more loops here
}
}
}
}
@code-reaper08
code-reaper08 / Substring.js
Created July 24, 2021 17:27
2nd for loop
let inpstring = "abc";
let n = inpstring.length;
function FindSubstring(Str, n){
for(let i=0; i<n ;i++){
for(let j=i;j<n;j++){
// another for loop comes here
}
}
}
@code-reaper08
code-reaper08 / Substring.js
Last active July 24, 2021 17:50
3rd for loop
let inpstring = "abc";
let n = inpstring.length;
function FindSubstring(Str, n){
for(let i=0; i<n ;i++){
for(let j=i;j<n;j++){
for(let k=i;k<j+1;k++){
console.log(Str.charAt(k))
}
}
}
@code-reaper08
code-reaper08 / Substring.js
Created July 24, 2021 17:49
calling function
let inpstring = "abc";
let n = inpstring.length;
function FindSubstring(Str, n){
for(let i=0; i<n ;i++){
/* console.log(i) */
for(let j=i;j<n;j++){
for(let k=i;k<j+1;k++){
console.log(Str.charAt(k))
}
}
let inpstring = "abc";
let n = inpstring.length;
function FindSubstring(Str, n){
for(let i=0; i<n ;i++){
/* console.log(i) */
for(let j=i;j<n;j++){
for(let k=i;k<j+1;k++){
console.log(Str.charAt(k))
}
}