Skip to content

Instantly share code, notes, and snippets.

@Astrobam
Astrobam / strncasecmp.js
Created May 5, 2016 20:13
JavaScript Version of strncasecmp.js
"use strict";
/*
Example Usage: node strncasecmp.js "Some String" "Some String" 5
*/
String.prototype.strncasecmp = function(str , len) {
let lowerThis = this.substr(0,len).toLowerCase();
let lowerStr = str.substr(0,len).toLowerCase();
return lowerThis>lowerStr ? 1 : (lowerThis<lowerStr ? -1 : 0);
};
@Astrobam
Astrobam / strcasecmp.js
Created May 5, 2016 19:18
JavaScript strcasecmp: String.prototype.strcasecmp
"use strict";
String.prototype.strcasecmp = function(str) {
let lowerThis = this.toLowerCase();
let lowerStr = str.toLowerCase();
return lowerThis>lowerStr ? 1 : (lowerThis<lowerStr ? -1 : 0);
};
//Code below this point is only required to test via command line.
if (typeof process !== "undefined") {
const args = process.argv;
@Astrobam
Astrobam / strcmp.js
Last active May 5, 2016 19:04
strcmp in javascript
"use strict";
String.prototype.strcmp = function(str) {
return this>str ? 1 : (this<str ? -1 : 0);
}
//Code below this point is only required to test via command line.
if (typeof process !== "undefined") {
const args = process.argv;
const nodeLocation = args[ 0 ];
const myfileName = args[ 1 ];
@Astrobam
Astrobam / brackets.js
Last active May 5, 2016 19:21
Node JS Code to check for Balanced Brackets of strings.
"use strict";
/*
Node Usage: node brackets.js "{[asd]}" "(test)" "[{UNBALANCED)]"
*/
String.prototype.validateBrackets = function () {
let allBrackets = "{}[]()",
bracketStack = [],
//Length of string
len = this.length,
indx,//index of char