Skip to content

Instantly share code, notes, and snippets.

@nickheal
nickheal / main.js
Created November 20, 2020 15:12
Complicated clear code
function myFunction(name, telephone, email) {
const requiredFields = name && telephone;
if (!requiredFields) {
const modalContainer = document.getElementById('modal-container');
const modal = document.createElement('div');
const basicString = 'Encountered a problem submitting the form. Missing '
if (!name && !telephone) {
modal.textContent = basicString + 'name & telephone fields.';
} else if (!name) {
@nickheal
nickheal / main.js
Created November 20, 2020 11:27
Complicated concise code
function myFunction(name, telephone, email) {
if (!name || !telephone) {
const modalContainer = document.getElementById('modal-container');
const modal = document.createElement('div');
const basicString = 'Encountered a problem submitting the form. Missing '
if (!name && !telephone) {
modal.textContent = basicString + 'name & telephone fields.';
} else if (!name) {
modal.textContent = basicString + 'name field.';
} else {
@nickheal
nickheal / main.js
Last active November 20, 2020 10:58
Clear code
function submitForm(name, telephone, email) {
const requiredFields = name && telephone;
if (!requiredFields) {
showAlert();
return;
}
postForm();
}
@nickheal
nickheal / main.js
Last active November 20, 2020 10:57
Concise code
function submitForm(name, telephone, email) {
if (!name || !telephone) {
showAlert();
return;
}
postForm();
}
@nickheal
nickheal / groupSentencesUpTo5000.js
Created April 11, 2020 14:26
The joy of partial application
import groupSentencesUpToX from './groupSentencesUpToX';
export default groupSentencesUpToX(?, 5000);
@nickheal
nickheal / sentiment.js
Created April 11, 2020 14:23
The joy of pipelines part 2
import { JSDOM } from 'jsdom';
import getElements from './common/getElements';
import fetchSentiments from './common/fetchSentiments';
import formatSentiments from './common/formatSentiments';
import getSentences from './common/getSentences';
import groupSentencesUpTo5000 from './common/groupSentencesUpTo5000';
import stripNonSentences from './common/stripNonSentences';
/**
* Gets the 'sentiment' of an HTML page using the AWS Comprehend API
@nickheal
nickheal / averageWordLength.js
Created April 11, 2020 13:42
The joy of pipelines
import { JSDOM } from 'jsdom';
import getAverageWordLength from './common/getAverageWordLength';
import getElements from './common/getElements';
import getSentences from './common/getSentences';
import getWords from './common/getWords';
import stripSpecialCharacters from './common/stripSpecialCharacters';
/**
* Gets the average word length from a page
* @param {string} html - the html to process