Skip to content

Instantly share code, notes, and snippets.

View MinSomai's full-sized avatar
🇳🇵
from the land of Mountains, Nepal. Namaste!

Min Somai MinSomai

🇳🇵
from the land of Mountains, Nepal. Namaste!
View GitHub Profile
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Binary Agents.js
Created May 31, 2020 15:56
Intermediate Algorithm Scripting: Binary Agents
function binaryAgent(str) {
let newStr = str.split(" ");
return newStr.map(item=>{
return String.fromCharCode(parseInt(item, 2));
}).join("");
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Steamroller.js
Created May 31, 2020 15:41
Intermediate Algorithm Scripting: Steamroller
function steamrollArray(arr) {
let stringFormat = arr.toString().split(",");
return stringFormat.filter(item=>item != '').map(item=>{
if(item == "[object Object]"){
return {};
}else{
return parseInt(item) ? parseInt(item) : item;
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Drop it.js
Created May 31, 2020 15:22
Intermediate Algorithm Scripting: Drop it
function dropElements(arr, func) {
let newArray = [];
let checkedItem = [];
arr.map((item, index)=>{
let alreadyDeleted = checkedItem.some(innerItem=>innerItem==item);
if(alreadyDeleted) newArray.push(arr[index]);
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Smallest Common Multiple.js
Created May 31, 2020 15:21
Intermediate Algorithm Scripting: Smallest Common Multiple
function smallestCommons(arr) {
let numbers = arr.sort((a, b)=>a-b);
for(let i = numbers[0]; i <= numbers[1]; i++){
numbers.push(i);
}
return numbers.reduce((a, b) => {
return lcm(a, b);
});
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Sum All Primes.js
Created May 29, 2020 16:30
Intermediate Algorithm Scripting: Sum All Primes
function sumPrimes(num) {
let i,flag,j;
let sum = 0;
for(i=1; i<=num; i++)
{
flag=0;
for(j=1; j<=num; j++)
{
if(i%j==0)
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers.js
Created May 29, 2020 16:17
Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers
function sumFibs(num) {
let temp = 0, temp2 = 1,
nextTerm, sum = 0;
while(temp < num){
nextTerm = temp + temp2;
temp = temp2;
temp2 = nextTerm;
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Convert HTML Entities.js
Created May 29, 2020 15:50
Intermediate Algorithm Scripting: Convert HTML Entities
function convertHTML(str) {
return str.replace(/[&<>"']/g, (match) => {
switch(match){
case "&":
return "&amp;";
case '"':
return "&quot;";
case "'":
return "&apos;";
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Sorted Union.js
Created May 29, 2020 15:04
Intermediate Algorithm Scripting: Sorted Union
function uniteUnique(...arr) {
let resultArray = arr[0];
for(let i = 0; i < arr.length-1; i++){
resultArray = compareArrays(resultArray, arr[i+1]);
}
return resultArray;
}
@MinSomai
MinSomai / Intermediate Algorithm Scripting: Missing letters.js
Created May 29, 2020 14:31
Intermediate Algorithm Scripting: Missing letters
function fearNotLetter(str) {
let charCodes = str.split("").map(code=>{
return code.charCodeAt(0);
}).sort((a, b)=>a-b);
let missingCode = charCodes[0];
for(let i = 0; i < charCodes.length; i++){
if(missingCode == charCodes[i]-1){
@MinSomai
MinSomai / Intermediate Algorithm Scripting: DNA Pairing.js
Created May 29, 2020 14:05
Intermediate Algorithm Scripting: DNA Pairing
function pairElement(str) {
let pairedDNA = [];
str.split("").forEach(strand=>{
let paired;
switch(strand){
case 'G':
paired = ['G', 'C'];