Skip to content

Instantly share code, notes, and snippets.

View newbenhd's full-sized avatar
😊

Ben M newbenhd

😊
  • Loading...
  • Chicago, Illinois
View GitHub Profile
return new Promise(async (resolve, reject) => {
try {
const depnString = JSON.stringify(this.depn);
await fs.writeFile(path.join(this.dest, this.fileName), depnString);
} catch (err) {
reject(err);
}
});
"use strict"
const bodyParser = require('body-parser')
const serveStatic = require('serve-static')
function wrapper = () => {
const locals = {}
return (path, callback) => {
on,
}
}
import config from '../config'
import { User } from '../resources/user/user.model'
import jwt from 'jsonwebtoken'
export const newToken = user => {
return jwt.sign({ id: user.id }, config.secrets.jwt, {
expiresIn: config.secrets.jwtExp
})
}
if (typeof module !== 'undefined') {
var JSONParser = require('../src/main.js');
var expect = require('chai').expect;
}
describe('JSON Parser', function() {
describe('Numbers', function() {
it('should work on single-digit', function() {
expect(JSONParser(JSON.stringify(1))).to.eql(1);
/**
* returns a javascript object from a JSON formatted string
* Example json to javascript object:
* "5" -> 5
* "'hello'" -> 'hello'
* "[]" -> []
* "{}" -> {}
* "["hello"]" -> ['hello']
*
* For more examples, use the JSON.stringify method in the console
@newbenhd
newbenhd / prototype
Created June 18, 2019 22:03
Prototype Inheritance
function createArray() {
this.array = [];
}
createArray.prototype.push = val => {
this.array.push(val);
};
@newbenhd
newbenhd / Censor
Created May 24, 2019 19:28
Censor function
// 1. Declare a function named censor with no parameter.
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object.
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2.
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2.
// 1-2-2. Else, iterate through censorObject using for...in looop
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key using regex and String.replace method.
// 1-2-2-2. Return str1.
// 1-3. Return getCensor.
function censor() {
@newbenhd
newbenhd / censor.js
Last active May 24, 2019 19:10
Censor function
/*
Challenge:
Create a function censor that accepts no arguments. censor will return a function that will accept either two strings, or one string. When two strings are given, the returned function will hold onto the two strings as a pair, for future use. When one string is given, the returned function will return the same string, except all instances of a first string (of a saved pair) will be replaced with the second string (of a saved pair).
*/
// 1. Declare a function named censor with no parameter.
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object.
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2.
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2.
// 1-2-2. Else, iterate through censorObject using for...in looop
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key
@newbenhd
newbenhd / censor.js
Last active May 24, 2019 19:07
Create a function censor that accepts no arguments. censor will return a function that will accept either two strings, or one string. When two strings are given, the returned function will hold onto the two strings as a pair, for future use. When one string is given, the returned function will return the same string, except all instances of a fi…
/*
Challenge:
Create a function censor that accepts no arguments. censor will return a function that will accept either two strings, or one string. When two strings are given, the returned function will hold onto the two strings as a pair, for future use. When one string is given, the returned function will return the same string, except all instances of a first string (of a saved pair) will be replaced with the second string (of a saved pair).
*/
// 1. Declare a function named censor with no parameter.
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object.
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2.
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2.
// 1-2-2. Else, iterate through censorObject using for...in looop
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key
@newbenhd
newbenhd / sample.js
Last active May 24, 2019 19:03
Sample
// 1. Declare a function named censor with no parameter.
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object.
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2.
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2.
// 1-2-2. Else, iterate through censorObject using for...in looop
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key using regex and String.replace method.
// 1-2-2-2. Return str1.
// 1-3. Return getCensor.
function censor() {