Skip to content

Instantly share code, notes, and snippets.

@rtviner
rtviner / longestSubstring
Created Jun 11, 2019
Sliding Window Find Longest Substring
View longestSubstring
findLongestSubstring Solution
function findLongestSubstring(str) {
let longest = 0;
let seen = {};
let start = 0;
for (let i = 0; i < str.length; i++) {
let char = str[i];
if (seen[char]) {
start = Math.max(start, seen[char]);
View countdown.js
function countdown (minutes) {
for (let seconds = minutes * 60 ; seconds >= 0; seconds--) {
setTimeout(() => tick(seconds), 1000);
}
function tick (seconds) {
let secondsView = ((seconds%60) >= 10) ? seconds%60 : `0${seconds%60}`;
console.log(`${Math.floor(seconds/60)||"00"}:${secondsView||"00"}`);
}
View calculator.js
let outputValue = document.getElementById('output');
let numbers = document.querySelectorAll('.num-btn');
let decimal = document.getElementById('dec-btn')
let operators = document.querySelectorAll('.op-btn');
let equals = document.getElementById('equal-btn');
let clear = document.getElementById('clear');
let inputValue = [];
function add(num1, num2) {
return num1 + num2;