Skip to content

Instantly share code, notes, and snippets.

View greemwahr's full-sized avatar
🎯
Focusing

Greemwahr greemwahr

🎯
Focusing
  • Anonymous
View GitHub Profile
function duplicates(arr) {
var mergedArray = [].concat.apply([], arr);
console.log(mergedArray);
var arrSorted = mergedArray.sort(function (a, b) {
return a - b;
});
console.log(arrSorted);
function move_zeros(arrNum, isRight){
isRight = typeof isRight === 'undefined' ? true : isRight;
// console.log(arrNum);
// console.log(isRight);
var arrNumLength = arrNum.length;
function eliminateZeros(element) {
return element !== 0;
}
/* Excellent piece of code to determine the index of a particular
element being searched.*/
var indices = [];
var element = 0;
var idx = arrNum.indexOf(element);
// console.log(idx);
while (idx != -1) {
indices.push(idx);
idx = arrNum.indexOf(element, idx + 1);
@greemwahr
greemwahr / isPrime.js
Created November 1, 2015 02:21
codeSnippet
function isPrime(num) {
var absNum = Math.abs(num);
if (absNum <= 1) {
return false;
} else if (absNum <= 3) {
return true;
} else if (absNum % 2 === 0 || absNum % 3 === 0) {
return false;
}
function alphabetPosition(text) {
var textWithoutSymbols = text.replace(/[^\w]|_|\d/g, "").toLowerCase();
var objAlphabet = {"a" : 1, "b" : 2, "c" : 3, "d" : 4, "e" : 5, "f" : 6, "g" : 7, "h" : 8, "i" : 9, "j" : 10, "k" : 11, "l" : 12, "m" : 13, "n" : 14, "o" : 15, "p" : 16, "q" : 17, "r" : 18, "s" : 19, "t" : 20, "u" : 21, "v" : 22, "w" : 23, "x" : 24, "y" : 25, "z" : 26}
var alphaNumericCypher = textWithoutSymbols.split("").map(function (a) {
for(var key in objAlphabet) {
if(objAlphabet.hasOwnProperty(key)) {
if (key === a) return objAlphabet[key];
}
@greemwahr
greemwahr / isIsogram.js
Created November 2, 2015 01:03
codeSnippet
function isIsogram(str){
//.....
if (str === null) {
return false;
} else {
var strInput = str.toLowerCase();
var repeatedChr = (/([a-zA-Z]).*?\1/).test(strInput);
return !repeatedChr;
}
}
function factorialize(num) {
factorialArr = [];
if (num === 0) {
factorialArr = [1];
} else {
for (i = 1; i < num + 1; i++) {
factorialArr.push(i);
}
}
<html>
<head>
<title>Information Gathered</title>
</head>
<body>
<!--
You embed PHP code between tags
# Process I/O files synchronously in node.js
var fs = require('fs')
var contents = fs.readFileSync(process.argv[2])
var lines = contents.toString().split('\n').length - 1
console.log(lines)
// note you can avoid the .toString() by passing 'utf8' as the
// second argument to readFileSync, then you'll get a String!
var fs = require('fs')
var path = require('path')
fs.readdir(process.argv[2], function (err, list) {
list.forEach(function (file) {
if (path.extname(file) === '.' + process.argv[3])
console.log(file)
})
})