Skip to content

Instantly share code, notes, and snippets.

@QaisPalekar
QaisPalekar / index.js
Created May 5, 2020 01:30
Given an array of words, return the words that can be typed using letters of only one row on a keyboard.
function getOneKeyRowWords(listOfWords) {
const row1 = ['q','w','e','r','t','y','u','i','o','p'],
row2 = ['a','s','d','f','g','h','j','k','l'],
row3 = ['z','x','c','v','b','n','m'];
return listOfWords.filter((word) => {
const uniquesChars = new Set(word.toLowerCase());
return (
row1.length === [...new Set([...row1, ...uniquesChars])].length ||
row2.length === [...new Set([...row2, ...uniquesChars])].length ||
row3.length === [...new Set([...row3, ...uniquesChars])].length
@QaisPalekar
QaisPalekar / gist:50a335a89db82d7582710544334f6d8d
Last active January 23, 2020 06:24
Given a number, return true if the input is a factorial of any natural number
function isFactorial(num) {
let remainder = num;
let factorial = 2;
while(remainder >= factorial) {
remainder = remainder/factorial;
factorial++;
}
return remainder===1;
}

Cheat Sheet

Headings