View longestSubString.js
/** | |
Find the longest substring in string. Output the length of the substring | |
e.g | |
s = 'ababc' | |
sub = 3 | |
*/ | |
const s = 'ababc'; |
View spacedIndexing.js
/** | |
Write a function that takes three arguments, 2 arrays (a and b) and 1 integer (c) | |
then returns one array (d) which is created by inserting all elements in b into a at indexes | |
which are spaced by the integer value. | |
Consider all possible corner cases and print out the final array (d). | |
e.g | |
a = ["a", "b", "c", "d", "e", "f"] | |
b = ["1", "2", "3"] | |
c = 2 |
View wordColor.js
var colors = ["black", "blue", "brown", "green"]; | |
var doc = document.getElementById("content"); | |
var text = doc.innerHTML.split(" "); | |
function changeColor() { | |
doc.innerHTML = ""; | |
text.forEach(function(word, i) { | |
if (i != text.length) { | |
word += "\n"; |
View bubbleSort.js
// O (N^2) | |
var theArray = Array.prototype.slice.call(process.argv[2]); | |
var startTime | |
var endTime | |
console.log(theArray, 'unSorted') | |
function swapValues(one, two) { | |
var temp = theArray[one] | |
theArray[one] = theArray[two] |
View ref.js
var express = require('express'); | |
var path = require('path'); | |
var favicon = require('static-favicon'); | |
var logger = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); | |
var session = require('express-session') | |
var mongoose = require('mongoose'); | |
var nodemailer = require('nodemailer'); | |
var passport = require('passport'); |
View service worker.js
var cacheName = 'weatherPWA-step-6-1'; | |
var dataCacheName = 'weatherData-v1'; | |
var filesToCache = [ | |
'/', | |
'/index.html', | |
'/scripts/app.js', | |
'/styles/inline.css', | |
'/images/clear.png', | |
'/images/cloudy-scattered-showers.png', | |
'/images/cloudy.png', |
View caesarCipher.js
/** | |
* Returns the result of having each alphabetic letter of the given text string shifted forward | |
* by the given amount, with wraparound. Case is preserved, and non-letters are unchanged. | |
* | |
* i.e. | |
* | |
* - caesarShift({ text: "abz", shift: 0 }) = "abz". | |
* - caesarShift({ text: "abz", shift: 1 }) = "bca". | |
* - caesarShift({ text: "abz", shift: 25 }) = "zay". | |
* - caesarShift({ text: "THe 123 !@#$", shift: 13 }) = "GUr 123 !@#$". |
View cache.js
let cache = {} | |
const complex_computation = (a, b, timeout=5000, callback) => { | |
setTimeout(() => { | |
callback(null, a + b) | |
}, timeout) | |
} | |
const cached_computation = (a, b, callback) => { | |
const key = a + ':' + b |
View staircase.js
// Time Complexity O(n2) | |
const staircase = (n, c) => { | |
let y = []; | |
let s; | |
for (let i = 1; i <= n; i++) y[i - 1] = i; | |
for (let j = 1; j <= n; j++) { | |
s = y.length - j; | |
console.log(' '.repeat(s), c.repeat(j)); |
View callback.js
Array.prototype.click = function(fn, thisArg) { | |
const _self = thisArg || this; | |
for (let i = 0; i < _self.length; i++) { | |
fn.apply(thisArg, [_self[i], i, thisArg]); | |
// Mutation. | |
thisArg.values[i] = i; | |
} | |
}; |
NewerOlder