├── docs ├── CNAME ├── favicon.png ├── logos │ ├── logo_128.png │ ├── logo_256.png │ ├── logo_32.png │ ├── logo_384.png │ ├── logo_512.png │ ├── logo_64.png │ ├── logo_128_o.png │ ├── logo_32_white.png │ ├── logo_64_white.png │ ├── logo_128_white.png │ ├── logo_256_white.png │ ├── logo_384_white.png │ └── logo_512_white.png ├── icons │ ├── chevron-left.svg │ ├── chevron-right.svg │ ├── star.svg │ ├── code.svg │ └── law.svg └── clipboard.svg ├── logo.png ├── sponsored_by_DigitalOcean.png ├── glossary ├── Class.md ├── Stream.md ├── CoffeeScript.md ├── SEO.md ├── DNS.md ├── NoSQL.md ├── String.md ├── Integer.md ├── Boolean.md ├── TypeScript.md ├── WebRTC.md ├── Scope.md ├── Repository.md ├── Higher-order-function.md ├── MDN.md ├── Yarn.md ├── Template-literals.md ├── Vue.md ├── Automatic-semicolon-insertion.md ├── Constant.md ├── Pseudo-class.md ├── Pseudo-element.md ├── Module.md ├── Flexbox.md ├── Garbage-collection.md ├── MongoDB.md ├── URI.md ├── UTF-8.md ├── Argument.md ├── SVG.md ├── XHTML.md ├── URL.md ├── Closure.md ├── React.md ├── Variable.md ├── Express.md ├── Hoisting.md ├── Npm.md ├── jQuery.md ├── Factory-functions.md ├── Node-js.md ├── SSL.md ├── WebSockets.md ├── Character-encoding.md ├── SQL-injection.md ├── Git.md ├── Unit-testing.md ├── Constructor.md ├── CORS.md ├── Regular-expressions.md ├── Array.md ├── Callback.md ├── HTML.md ├── XML.md ├── Continuous-Integration.md ├── Currying.md ├── Selector.md ├── Domain-name.md ├── WebGL.md ├── AJAX.md ├── Asynchronous-programming.md ├── CSS.md ├── Element.md ├── Integration-testing.md ├── JSON.md ├── Mutabe-value.md ├── Responsive-web-design.md ├── Viewport.md ├── API.md ├── ES6.md ├── Serialization.md ├── Continuous-Deployment.md ├── Domain-name-registrar.md ├── WebAssembly.md ├── Deserialization.md ├── First-class-function.md ├── Object.md ├── SQL.md ├── PWA.md ├── Cross-site-scripting-xss.md ├── Functor.md ├── Object-oriented-programming.md ├── Prepared-statements.md ├── Promise.md ├── Prototype-based-programming.md ├── MVC.md ├── WebComponents.md ├── Event-loop.md ├── Functional-programming.md ├── CSV.md ├── IP.md ├── Strict-mode.md ├── HTTP-and-HTTPS.md ├── Event-driven-programming.md ├── Function.md ├── Recursion.md ├── ShadowDOM.md └── DOM.md ├── test ├── defer.test.js ├── hasFlags.test.js ├── redirect.test.js ├── runAsync.test.js ├── setStyle.test.js ├── checkProp.test.js ├── dayOfYear.test.js ├── JSONToFile.test.js ├── hashBrowser.test.js ├── scrollToTop.test.js ├── smoothScroll.test.js ├── httpsRedirect.test.js ├── readFileLines.test.js ├── arrayToHtmlList.test.js ├── detectDeviceType.test.js ├── observeMutations.test.js ├── speechSynthesis.test.js ├── onUserInputChange.test.js ├── UUIDGeneratorBrowser.test.js ├── createDirIfNotExists.test.js ├── recordAnimationFrames.test.js ├── btoa.test.js ├── pipeLog.test.js ├── sleep.test.js ├── kmphToMph.test.js ├── prefix.test.js ├── sum.test.js ├── timeTaken.test.js ├── isBrowser.test.js ├── mphToKmph.test.js ├── sdbm.test.js ├── call.test.js ├── colorize.test.js ├── digitize.test.js ├── heronArea.test.js ├── isDivisible.test.js ├── isSymbol.test.js ├── isUndefined.test.js ├── reverseString.test.js ├── mapKeys.test.js ├── initial.test.js ├── mapNumRange.test.js ├── radsToDegrees.test.js ├── unary.test.js ├── unionBy.test.js ├── RGBToHex.test.js ├── bottomVisible.test.js ├── currentURL.test.js ├── negate.test.js ├── deepFlatten.test.js ├── difference.test.js ├── distance.test.js ├── fibonacci.test.js ├── hammingDistance.test.js ├── powerset.test.js ├── primes.test.js ├── serializeCookie.test.js ├── coalesce.test.js ├── escapeRegExp.test.js ├── findLast.test.js ├── similarity.test.js ├── fibonacciCountUntilNum.test.js ├── fibonacciUntilNum.test.js ├── omit.test.js ├── parseCookie.test.js ├── removeNonASCII.test.js ├── clampNumber.test.js ├── cloneRegExp.test.js ├── defaults.test.js ├── intersection.test.js ├── isBrowserTabFocused.test.js ├── pick.test.js ├── remove.test.js ├── tail.test.js ├── times.test.js ├── truncateString.test.js ├── dropWhile.test.js ├── over.test.js ├── pull.test.js ├── findLastIndex.test.js ├── isEven.test.js ├── nodeListToArray.test.js ├── takeRightWhile.test.js ├── objectToPairs.test.js ├── toDecimalMark.test.js ├── xProd.test.js ├── atob.test.js ├── debounce.test.js ├── hz.test.js ├── objectFromPairs.test.js ├── vectorDistance.test.js ├── ary.test.js ├── forOwn.test.js ├── isNull.test.js ├── unflattenObject.test.js ├── unfold.test.js ├── curry.test.js ├── isPrime.test.js ├── omitBy.test.js ├── forEachRight.test.js ├── pickBy.test.js ├── sortCharactersInString.test.js ├── stripHTMLTags.test.js ├── JSONToDate.test.js ├── dropRightWhile.test.js ├── hasClass.test.js ├── hide.test.js ├── show.test.js ├── stableSort.test.js ├── escapeHTML.test.js ├── get.test.js ├── throttle.test.js ├── pullBy.test.js ├── isBoolean.test.js ├── percentile.test.js ├── unescapeHTML.test.js ├── degreesToRads.test.js ├── delay.test.js ├── getStyle.test.js ├── httpGet.test.js ├── httpPut.test.js ├── isFunction.test.js ├── isSimilar.test.js ├── removeVowels.test.js ├── createElement.test.js ├── flip.test.js ├── forOwnRight.test.js ├── getDaysDiffBetweenDates.test.js ├── httpPost.test.js ├── bifurcate.test.js ├── bifurcateBy.test.js ├── getColonTimeFromDate.test.js ├── palindrome.test.js ├── size.test.js ├── unionWith.test.js ├── differenceWith.test.js ├── rearg.test.js ├── countVowels.test.js ├── httpDelete.test.js ├── lcm.test.js ├── mapValues.test.js ├── partial.test.js ├── solveRPN.test.js ├── attempt.test.js ├── bindAll.test.js ├── flatten.test.js ├── intersectionBy.test.js ├── maxN.test.js ├── minN.test.js ├── spreadOver.test.js ├── toggleClass.test.js ├── cleanObj.test.js ├── compact.test.js ├── composeRight.test.js ├── when.test.js ├── compose.test.js ├── countBy.test.js ├── decapitalize.test.js ├── overArgs.test.js ├── partialRight.test.js ├── splitLines.test.js ├── sumBy.test.js ├── insertAfter.test.js ├── isArmstrongNumber.test.js ├── once.test.js ├── coalesceFactory.test.js ├── extendHex.test.js ├── gcd.test.js ├── hashNode.test.js ├── indexOfAll.test.js ├── insertBefore.test.js ├── pipeFunctions.test.js ├── shallowClone.test.js ├── getURLParameters.test.js ├── isPlainObject.test.js ├── toHash.test.js ├── indentString.test.js ├── maxDate.test.js ├── minDate.test.js ├── takeRight.test.js ├── isNil.test.js ├── runPromisesInSeries.test.js ├── bind.test.js ├── isTravisCI.test.js ├── symmetricDifferenceBy.test.js ├── unzipWith.test.js ├── maxBy.test.js ├── minBy.test.js ├── pullAtIndex.test.js ├── triggerEvent.test.js ├── counter.test.js ├── reduceSuccessive.test.js ├── mostPerformant.test.js ├── pullAtValue.test.js ├── takeWhile.test.js ├── transform.test.js ├── isNumber.test.js ├── isUpperCase.test.js ├── truthCheckCollection.test.js ├── averageBy.test.js ├── differenceBy.test.js ├── findKey.test.js ├── isNegativeZero.test.js ├── isSameDate.test.js ├── renameKeys.test.js ├── bindKey.test.js ├── isArrayLike.test.js ├── countOccurrences.test.js ├── getType.test.js ├── initializeNDArray.test.js ├── isAfterDate.test.js ├── collectInto.test.js ├── flattenObject.test.js ├── merge.test.js ├── elo.test.js ├── findLastKey.test.js ├── isLowerCase.test.js ├── drop.test.js ├── isBeforeDate.test.js ├── squareSum.test.js ├── symmetricDifference.test.js ├── zipWith.test.js ├── UUIDGeneratorNode.test.js ├── intersectionWith.test.js ├── median.test.js ├── functions.test.js ├── luhnCheck.test.js ├── pipeAsyncFunctions.test.js ├── sample.test.js ├── nthArg.test.js └── reject.test.js ├── .gitignore ├── .github └── ISSUE_TEMPLATE │ ├── discussion.md │ └── feature_request.md ├── .mdlrc.style.rb ├── snippets ├── currentURL.md ├── isSymbol.md ├── isNull.md ├── isString.md ├── distance.md ├── escapeRegExp.md ├── degreesToRads.md ├── head.md ├── isFunction.md ├── negate.md ├── radsToDegrees.md ├── isBoolean.md ├── isDivisible.md ├── nodeListToArray.md ├── removeNonASCII.md ├── stripHTMLTags.md ├── isUndefined.md ├── isAfterDate.md ├── isBeforeDate.md ├── isEven.md ├── shallowClone.md ├── sum.md ├── hide.md ├── everyNth.md ├── getStyle.md ├── objectFromPairs.md ├── isNil.md ├── mapNumRange.md ├── functionName.md ├── getType.md ├── hasClass.md ├── isLowerCase.md ├── randomNumberInRange.md ├── splitLines.md ├── toDecimalMark.md ├── digitize.md ├── isNegativeZero.md ├── show.md ├── isUpperCase.md ├── serializeCookie.md ├── toggleClass.md ├── isBrowserTabFocused.md ├── last.md ├── objectToPairs.md ├── reverseString.md ├── getColonTimeFromDate.md ├── randomIntegerInRange.md ├── round.md ├── untildify.md ├── initial.md ├── isObjectLike.md ├── isSameDate.md ├── isWeekday.md ├── powerset.md ├── getDaysDiffBetweenDates.md ├── setStyle.md ├── isAbsoluteURL.md ├── uniqueElements.md ├── RGBToHex.md ├── createDirIfNotExists.md ├── union.md ├── redirect.md ├── toSafeInteger.md ├── unary.md ├── isStream.md ├── isWeekend.md ├── sleep.md ├── JSONToFile.md ├── coalesce.md ├── insertAfter.md ├── nthArg.md ├── sortCharactersInString.md ├── when.md ├── hammingDistance.md ├── isArrayLike.md ├── isTravisCI.md ├── minDate.md ├── truncateString.md ├── validateNumber.md ├── byteSize.md ├── cloneRegExp.md ├── insertBefore.md ├── isNumber.md ├── pick.md ├── randomHexColorCode.md ├── delay.md ├── maxDate.md ├── drop.md ├── isPlainObject.md ├── midpoint.md ├── partial.md ├── filterNonUnique.md ├── castArray.md ├── filterFalsy.md ├── partialRight.md ├── tail.md └── take.md ├── snippets_archive ├── collatz.md ├── celsiusToFahrenheit.md ├── fahrenheitToCelsius.md ├── pipeLog.md ├── kmphToMph.md ├── mphToKmph.md ├── countVowels.md ├── squareSum.md ├── removeVowels.md ├── JSONToDate.md └── fibonacciCountUntilNum.md ├── snippet-template.md ├── .npmignore └── vscode_snippets └── README.md /docs/CNAME: -------------------------------------------------------------------------------- 1 | 30secondsofcode.org 2 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/logo.png -------------------------------------------------------------------------------- /docs/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/favicon.png -------------------------------------------------------------------------------- /docs/logos/logo_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_128.png -------------------------------------------------------------------------------- /docs/logos/logo_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_256.png -------------------------------------------------------------------------------- /docs/logos/logo_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_32.png -------------------------------------------------------------------------------- /docs/logos/logo_384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_384.png -------------------------------------------------------------------------------- /docs/logos/logo_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_512.png -------------------------------------------------------------------------------- /docs/logos/logo_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_64.png -------------------------------------------------------------------------------- /docs/logos/logo_128_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_128_o.png -------------------------------------------------------------------------------- /docs/logos/logo_32_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_32_white.png -------------------------------------------------------------------------------- /docs/logos/logo_64_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_64_white.png -------------------------------------------------------------------------------- /docs/logos/logo_128_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_128_white.png -------------------------------------------------------------------------------- /docs/logos/logo_256_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_256_white.png -------------------------------------------------------------------------------- /docs/logos/logo_384_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_384_white.png -------------------------------------------------------------------------------- /docs/logos/logo_512_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/docs/logos/logo_512_white.png -------------------------------------------------------------------------------- /sponsored_by_DigitalOcean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WYseven/30-seconds-of-code/HEAD/sponsored_by_DigitalOcean.png -------------------------------------------------------------------------------- /glossary/Class.md: -------------------------------------------------------------------------------- 1 | ### Class 2 | 3 | In object-oriented programming, a class is a template definition of an object's properties and methods. 4 | -------------------------------------------------------------------------------- /glossary/Stream.md: -------------------------------------------------------------------------------- 1 | ### Stream 2 | 3 | A stream is a sequence of data made available over time, often due to network transmission or storage access times. 4 | -------------------------------------------------------------------------------- /glossary/CoffeeScript.md: -------------------------------------------------------------------------------- 1 | ### CoffeeScript 2 | 3 | CoffeeScript is a programming language inspired by Ruby, Python and Haskell that transpiles to JavaScript. 4 | -------------------------------------------------------------------------------- /glossary/SEO.md: -------------------------------------------------------------------------------- 1 | ### SEO 2 | 3 | SEO stands for Search Engine Optimization and refers to the process of improving a website's search rankings and visibility. 4 | -------------------------------------------------------------------------------- /test/defer.test.js: -------------------------------------------------------------------------------- 1 | const {defer} = require('./_30s.js'); 2 | 3 | test('defer is a Function', () => { 4 | expect(defer).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /glossary/DNS.md: -------------------------------------------------------------------------------- 1 | ### DNS 2 | 3 | A DNS (Domain Name System) translates domain names to the IP addresses needed to find a particular computer service on a network. 4 | -------------------------------------------------------------------------------- /glossary/NoSQL.md: -------------------------------------------------------------------------------- 1 | ### NoSQL 2 | 3 | NoSQL databases provide a mechanism to create, update, retrieve and calculate data that is stored in models that are non-tabular. -------------------------------------------------------------------------------- /glossary/String.md: -------------------------------------------------------------------------------- 1 | ### String 2 | 3 | Strings are one of the primitive data types in JavaScript. 4 | They are sequences of characters and are used to represent text. 5 | -------------------------------------------------------------------------------- /test/hasFlags.test.js: -------------------------------------------------------------------------------- 1 | const {hasFlags} = require('./_30s.js'); 2 | 3 | test('hasFlags is a Function', () => { 4 | expect(hasFlags).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/redirect.test.js: -------------------------------------------------------------------------------- 1 | const {redirect} = require('./_30s.js'); 2 | 3 | test('redirect is a Function', () => { 4 | expect(redirect).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/runAsync.test.js: -------------------------------------------------------------------------------- 1 | const {runAsync} = require('./_30s.js'); 2 | 3 | test('runAsync is a Function', () => { 4 | expect(runAsync).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/setStyle.test.js: -------------------------------------------------------------------------------- 1 | const {setStyle} = require('./_30s.js'); 2 | 3 | test('setStyle is a Function', () => { 4 | expect(setStyle).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /glossary/Integer.md: -------------------------------------------------------------------------------- 1 | ### Integer 2 | 3 | Integers are one of the primitive data types in Javascript. 4 | They represent a numerical value that has no fractional component. 5 | -------------------------------------------------------------------------------- /test/checkProp.test.js: -------------------------------------------------------------------------------- 1 | const {checkProp} = require('./_30s.js'); 2 | 3 | test('checkProp is a Function', () => { 4 | expect(checkProp).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/dayOfYear.test.js: -------------------------------------------------------------------------------- 1 | const {dayOfYear} = require('./_30s.js'); 2 | 3 | test('dayOfYear is a Function', () => { 4 | expect(dayOfYear).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /glossary/Boolean.md: -------------------------------------------------------------------------------- 1 | ### Boolean 2 | 3 | Booleans are one of the primitive data types in JavaScript. 4 | They represent logical data values and can only be `true` or `false`. 5 | -------------------------------------------------------------------------------- /glossary/TypeScript.md: -------------------------------------------------------------------------------- 1 | ### TypeScript 2 | 3 | TypeScript is a superset of JavaScript, adding optional static typing to the language. 4 | TypeScript compiles to plain JavaScript. 5 | -------------------------------------------------------------------------------- /glossary/WebRTC.md: -------------------------------------------------------------------------------- 1 | ### WebRTC 2 | 3 | WebRTC stands for Web Real-Time Communication and is an API that can be used for video-chat, voice-calling and P2P-file-sharing web apps. 4 | -------------------------------------------------------------------------------- /test/JSONToFile.test.js: -------------------------------------------------------------------------------- 1 | const {JSONToFile} = require('./_30s.js'); 2 | 3 | test('JSONToFile is a Function', () => { 4 | expect(JSONToFile).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/hashBrowser.test.js: -------------------------------------------------------------------------------- 1 | const {hashBrowser} = require('./_30s.js'); 2 | 3 | test('hashBrowser is a Function', () => { 4 | expect(hashBrowser).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/scrollToTop.test.js: -------------------------------------------------------------------------------- 1 | const {scrollToTop} = require('./_30s.js'); 2 | 3 | test('scrollToTop is a Function', () => { 4 | expect(scrollToTop).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | currentSnippet\.js 3 | *.md.temp.js 4 | .idea 5 | test.sh 6 | /*.log 7 | dist/flavor\.min\.css 8 | dist/flavor\.css 9 | test_old/ 10 | coverage/ 11 | -------------------------------------------------------------------------------- /glossary/Scope.md: -------------------------------------------------------------------------------- 1 | ### Scope 2 | 3 | Each function has its own scope, and any variable declared within that function is only accessible from that function and any nested functions. 4 | -------------------------------------------------------------------------------- /test/smoothScroll.test.js: -------------------------------------------------------------------------------- 1 | const {smoothScroll} = require('./_30s.js'); 2 | 3 | test('smoothScroll is a Function', () => { 4 | expect(smoothScroll).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /glossary/Repository.md: -------------------------------------------------------------------------------- 1 | ### Repository 2 | 3 | In a version control system, a repository (or repo for short) is a data structure that stores metadata for a set of files (i.e. a project). 4 | -------------------------------------------------------------------------------- /test/httpsRedirect.test.js: -------------------------------------------------------------------------------- 1 | const {httpsRedirect} = require('./_30s.js'); 2 | 3 | test('httpsRedirect is a Function', () => { 4 | expect(httpsRedirect).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/readFileLines.test.js: -------------------------------------------------------------------------------- 1 | const {readFileLines} = require('./_30s.js'); 2 | 3 | test('readFileLines is a Function', () => { 4 | expect(readFileLines).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /glossary/Higher-order-function.md: -------------------------------------------------------------------------------- 1 | ### Higher-order function 2 | 3 | Higher-order functions are functions that either take other functions as arguments, return a function as a result, or both. 4 | -------------------------------------------------------------------------------- /glossary/MDN.md: -------------------------------------------------------------------------------- 1 | ### MDN 2 | 3 | MDN Web Docs, formerly known as Mozilla Developer Network, is the official Mozilla website for development documentation of web standards and Mozilla projects. 4 | -------------------------------------------------------------------------------- /glossary/Yarn.md: -------------------------------------------------------------------------------- 1 | ### Yarn 2 | 3 | Yarn is a package manager made by Facebook. 4 | It can be used as an alternative to the npm package manager and is compatible with the public NPM registry. 5 | -------------------------------------------------------------------------------- /glossary/Template-literals.md: -------------------------------------------------------------------------------- 1 | ### Template literals 2 | 3 | Template literals are strings that allow embedded expressions. 4 | They support multi-line strings, expression interpolation and nesting. 5 | -------------------------------------------------------------------------------- /glossary/Vue.md: -------------------------------------------------------------------------------- 1 | ### Vue 2 | 3 | Vue.js is a progressive frontend framework for building user interfaces. 4 | Vue.js separates view and state, utilizing a virtual DOM to update the user interface. 5 | -------------------------------------------------------------------------------- /test/arrayToHtmlList.test.js: -------------------------------------------------------------------------------- 1 | const {arrayToHtmlList} = require('./_30s.js'); 2 | 3 | test('arrayToHtmlList is a Function', () => { 4 | expect(arrayToHtmlList).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/detectDeviceType.test.js: -------------------------------------------------------------------------------- 1 | const {detectDeviceType} = require('./_30s.js'); 2 | 3 | test('detectDeviceType is a Function', () => { 4 | expect(detectDeviceType).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/observeMutations.test.js: -------------------------------------------------------------------------------- 1 | const {observeMutations} = require('./_30s.js'); 2 | 3 | test('observeMutations is a Function', () => { 4 | expect(observeMutations).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/speechSynthesis.test.js: -------------------------------------------------------------------------------- 1 | const {speechSynthesis} = require('./_30s.js'); 2 | 3 | test('speechSynthesis is a Function', () => { 4 | expect(speechSynthesis).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /glossary/Automatic-semicolon-insertion.md: -------------------------------------------------------------------------------- 1 | ### Automatic semicolon insertion 2 | 3 | Automatic semicolon insertion (ASI) is a JavaScript feature that allows developers to omit semicolons in their code. 4 | -------------------------------------------------------------------------------- /glossary/Constant.md: -------------------------------------------------------------------------------- 1 | ### Constant 2 | 3 | A constant is a value, associated with an identifier. 4 | The value of a constant can be accessed using the identifier and cannot be altered during execution. 5 | -------------------------------------------------------------------------------- /test/onUserInputChange.test.js: -------------------------------------------------------------------------------- 1 | const {onUserInputChange} = require('./_30s.js'); 2 | 3 | test('onUserInputChange is a Function', () => { 4 | expect(onUserInputChange).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/discussion.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Discussion 3 | about: Discuss something with us 4 | 5 | --- 6 | 7 | ## Description 8 | 9 | -------------------------------------------------------------------------------- /.mdlrc.style.rb: -------------------------------------------------------------------------------- 1 | all 2 | rule 'header-style', :style => "atx" 3 | rule 'ul-style', :style => "asterisk" 4 | 5 | exclude_rule 'first-header-h1' 6 | exclude_rule 'first-line-h1' 7 | exclude_rule 'no-inline-html' 8 | -------------------------------------------------------------------------------- /glossary/Pseudo-class.md: -------------------------------------------------------------------------------- 1 | ### Pseudo-class 2 | 3 | In CSS, a pseudo-class is used to define a special state of an element and can be used as a selector in combination with an id, element or class selector. 4 | -------------------------------------------------------------------------------- /glossary/Pseudo-element.md: -------------------------------------------------------------------------------- 1 | ### Pseudo-element 2 | 3 | In CSS, a pseudo-element is used to style specific parts of an element and can be used as a selector in combination with an id, element or class selector. 4 | -------------------------------------------------------------------------------- /glossary/Module.md: -------------------------------------------------------------------------------- 1 | ### Module 2 | 3 | Modules are independent, self-contained pieces of code that can be incorporated into other pieces of code. 4 | Modules improve maintainability and reusability of the code. 5 | -------------------------------------------------------------------------------- /docs/icons/chevron-left.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /glossary/Flexbox.md: -------------------------------------------------------------------------------- 1 | ### Flexbox 2 | 3 | Flexbox is a one-dimensional layout model used to style websites as a property that could advance space distribution between items and provide powerful alignment capabilities. 4 | -------------------------------------------------------------------------------- /glossary/Garbage-collection.md: -------------------------------------------------------------------------------- 1 | ### Garbage collection 2 | 3 | Garbage collection is a form of automatic memory management. 4 | It attempts to reclaim memory occupied by objects that are no longer used by the program. 5 | -------------------------------------------------------------------------------- /glossary/MongoDB.md: -------------------------------------------------------------------------------- 1 | ### MongoDB 2 | 3 | MongoDB is a NoSQL database model that stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time 4 | -------------------------------------------------------------------------------- /glossary/URI.md: -------------------------------------------------------------------------------- 1 | ### URI 2 | 3 | URI stands for Uniform Resource Identifier and is a text string referring to a resource. 4 | A common type of URI is a URL, which is used for the identification of resources on the Web. 5 | -------------------------------------------------------------------------------- /glossary/UTF-8.md: -------------------------------------------------------------------------------- 1 | ### UTF-8 2 | 3 | UTF-8 stands for UCS Transformation Format 8 and is a commonly used character encoding. 4 | UTF-8 is backwards compatible with ASCII and can represent any standard Unicode character. 5 | -------------------------------------------------------------------------------- /test/UUIDGeneratorBrowser.test.js: -------------------------------------------------------------------------------- 1 | const {UUIDGeneratorBrowser} = require('./_30s.js'); 2 | 3 | test('UUIDGeneratorBrowser is a Function', () => { 4 | expect(UUIDGeneratorBrowser).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/createDirIfNotExists.test.js: -------------------------------------------------------------------------------- 1 | const {createDirIfNotExists} = require('./_30s.js'); 2 | 3 | test('createDirIfNotExists is a Function', () => { 4 | expect(createDirIfNotExists).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /test/recordAnimationFrames.test.js: -------------------------------------------------------------------------------- 1 | const {recordAnimationFrames} = require('./_30s.js'); 2 | 3 | test('recordAnimationFrames is a Function', () => { 4 | expect(recordAnimationFrames).toBeInstanceOf(Function); 5 | }); 6 | -------------------------------------------------------------------------------- /docs/icons/chevron-right.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /glossary/Argument.md: -------------------------------------------------------------------------------- 1 | ### Argument 2 | 3 | An argument is a value passed as an input to a function and can be either a primitive or an object. 4 | In JavaScript, functions can also be passed as arguments to other functions. 5 | -------------------------------------------------------------------------------- /glossary/SVG.md: -------------------------------------------------------------------------------- 1 | ### SVG 2 | 3 | SVG stands for Scalable Vector Graphics and is a 2D vector image format based on an XML syntax. 4 | SVG images can scale infinitely and can utilize clipping, masking, filters, animations etc. 5 | -------------------------------------------------------------------------------- /glossary/XHTML.md: -------------------------------------------------------------------------------- 1 | ### XHTML 2 | 3 | XHTML stands for EXtensible HyperText Markup Language and is a language used to structure web pages. 4 | XHTML is a reformulation of the HTML document structure as an application of XML. 5 | -------------------------------------------------------------------------------- /glossary/URL.md: -------------------------------------------------------------------------------- 1 | ### URL 2 | 3 | URL stands for Uniform Resource Locator and is a text string specifying where a resource can be found on the Internet. 4 | In the HTTP protocol, URLs are the same as web addresses and hyperlinks. 5 | -------------------------------------------------------------------------------- /glossary/Closure.md: -------------------------------------------------------------------------------- 1 | ### Closure 2 | 3 | A closure is the combination of a function and the lexical environment within which that function was declared. 4 | The closure allows a function to access the contents of that environment. 5 | -------------------------------------------------------------------------------- /glossary/React.md: -------------------------------------------------------------------------------- 1 | ### React 2 | 3 | React is a frontend framework, that allows developers to create dynamic, component-based user interfaces. 4 | React separates view and state, utilizing a virtual DOM to update the user interface. 5 | -------------------------------------------------------------------------------- /glossary/Variable.md: -------------------------------------------------------------------------------- 1 | ### Variable 2 | 3 | A variable is a storage location, associated with an identifier and containing a value. 4 | The value of a variable can be referred using the identifier and can be altered during execution. 5 | -------------------------------------------------------------------------------- /glossary/Express.md: -------------------------------------------------------------------------------- 1 | ### Express 2 | 3 | Express is a backend framework, that provides a layer of fundamental web application features for Node.js. 4 | Some of its key features are routing, middleware, template engines and error handling. 5 | -------------------------------------------------------------------------------- /glossary/Hoisting.md: -------------------------------------------------------------------------------- 1 | ### Hoisting 2 | 3 | Hoisting is JavaScript's default behavior of adding declarations to memory during the compile phase. 4 | Hoisting allows for JavaScript variables to be used before the line they were declared on. 5 | -------------------------------------------------------------------------------- /glossary/Npm.md: -------------------------------------------------------------------------------- 1 | ### Npm 2 | 3 | Npm is a package manager for the JavaScript programming language and the default package manager for Node.js. 4 | It consists of a command-line client and the npm registry, an online database of packages. 5 | -------------------------------------------------------------------------------- /glossary/jQuery.md: -------------------------------------------------------------------------------- 1 | ### jQuery 2 | 3 | jQuery is a frontend JavaScript library, that simplifies DOM manipulation, AJAX calls and Event handling. 4 | jQuery uses its globally defined function, `$()`, to select and manipulate DOM elements. 5 | -------------------------------------------------------------------------------- /docs/icons/star.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /glossary/Factory-functions.md: -------------------------------------------------------------------------------- 1 | ### Factory functions 2 | 3 | In JavaScript, a factory function is any function, which is not a class or constructor, that returns a new object. 4 | Factory functions don't require the use of the `new` keyword. 5 | -------------------------------------------------------------------------------- /glossary/Node-js.md: -------------------------------------------------------------------------------- 1 | ### Node.js 2 | 3 | Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. 4 | Node.js can execute JavaScript code outside of the browser and can be used to develop web backends or standalone applications. 5 | -------------------------------------------------------------------------------- /glossary/SSL.md: -------------------------------------------------------------------------------- 1 | ### SSL 2 | 3 | Secure Sockets Layer, commonly known as SSL or TLS, is a set of protocols and standards for transferring private data across the Internet. 4 | SSL uses a cryptographic system that uses two keys to encrypt data. 5 | -------------------------------------------------------------------------------- /glossary/WebSockets.md: -------------------------------------------------------------------------------- 1 | ### WebSockets 2 | 3 | WebSockets is a protocol that allows for a persistent client-server TCP connection. 4 | The WebSocket protocol uses lower overheads, facilitating real-time data transfer between client and server. 5 | -------------------------------------------------------------------------------- /docs/icons/code.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /glossary/Character-encoding.md: -------------------------------------------------------------------------------- 1 | ### Character encoding 2 | 3 | A character encoding defines a mapping between bytes and text, specifying how the sequenece of bytes should be interpreted. 4 | Two commonly used character encodings are ASCII and UTF-8. 5 | -------------------------------------------------------------------------------- /glossary/SQL-injection.md: -------------------------------------------------------------------------------- 1 | ### SQL injection 2 | 3 | SQL injection is a code injection technique, used to attack data-driven applications. 4 | SQL injections get their name from the SQL language and mainly target data stored in relational databases. 5 | -------------------------------------------------------------------------------- /glossary/Git.md: -------------------------------------------------------------------------------- 1 | ### Git 2 | 3 | Git is an open-source version control system, used for source code management. 4 | Git allows users to copy (clone) and edit code on their local machines, before merging it into the main code base (master repository). 5 | -------------------------------------------------------------------------------- /glossary/Unit-testing.md: -------------------------------------------------------------------------------- 1 | ### Unit testing 2 | 3 | Unit testing is a type of software testing, used to test individual units/components of a software. 4 | The purpose of unit tests are to validate that each individual unit/component performs as designed. 5 | -------------------------------------------------------------------------------- /glossary/Constructor.md: -------------------------------------------------------------------------------- 1 | ### Constructor 2 | 3 | In class-based object-oriented programming, a constructor is a special type of function called to instantiate an object. 4 | Constructors often accept arguments that are commonly used to set member properties. 5 | -------------------------------------------------------------------------------- /test/btoa.test.js: -------------------------------------------------------------------------------- 1 | const {btoa} = require('./_30s.js'); 2 | 3 | test('btoa is a Function', () => { 4 | expect(btoa).toBeInstanceOf(Function); 5 | }); 6 | test('btoa("foobar") equals "Zm9vYmFy"', () => { 7 | expect(btoa('foobar')).toBe('Zm9vYmFy'); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/CORS.md: -------------------------------------------------------------------------------- 1 | ### CORS 2 | 3 | Cross-Origin Resource Sharing (known as CORS) is a mechanism that uses extra HTTP headers to tell a browser to let a web application running at one domain have permission to access resources from a server at a different domain. 4 | -------------------------------------------------------------------------------- /glossary/Regular-expressions.md: -------------------------------------------------------------------------------- 1 | ### Regular expressions 2 | 3 | Regular expressions (known as regex or regexp) are patterns used to match character combinations in strings. 4 | JavaScript provides a regular expression implementation through the `RegExp` object. 5 | -------------------------------------------------------------------------------- /test/pipeLog.test.js: -------------------------------------------------------------------------------- 1 | const {pipeLog} = require('./_30s.js'); 2 | 3 | test('pipeLog is a Function', () => { 4 | expect(pipeLog).toBeInstanceOf(Function); 5 | }); 6 | test('pipeLog returns the given value', () => { 7 | expect(pipeLog('hi')).toBe('hi'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/sleep.test.js: -------------------------------------------------------------------------------- 1 | const {sleep} = require('./_30s.js'); 2 | 3 | test('sleep is a Function', () => { 4 | expect(sleep).toBeInstanceOf(Function); 5 | }); 6 | test('Works as expected', () => { 7 | return expect(sleep(1000)).resolves.toBe(undefined); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Array.md: -------------------------------------------------------------------------------- 1 | ### Array 2 | 3 | Arrays are used to store multiple values in a single variable. 4 | Arrays are ordered and each item in an array has a numeric index associated with it. 5 | JavaScript arrays are zero-indexed, meaning the first element's index is 0. 6 | -------------------------------------------------------------------------------- /glossary/Callback.md: -------------------------------------------------------------------------------- 1 | ### Callback 2 | 3 | A callback function, also known as a high-order function, is a function that is passed into another function as an argument, which is then executed inside the outer function. 4 | Callbacks can be synchronous or asynchronous. 5 | -------------------------------------------------------------------------------- /glossary/HTML.md: -------------------------------------------------------------------------------- 1 | ### HTML 2 | 3 | HTML stands for HyperText Markup Language and is a language used to structure web pages. 4 | HTML documents are plaintext documents structured with elements, which are surrounded by `<>` tags and optionally extended with attributes. 5 | -------------------------------------------------------------------------------- /glossary/XML.md: -------------------------------------------------------------------------------- 1 | ### XML 2 | 3 | XML stands for eXtensible Markup Language and is a generic markup language specified by the W3C. 4 | XML documents are plaintext documents structured with user-defined tags, surrounded by `<>` and optionally extended with attributes. 5 | -------------------------------------------------------------------------------- /test/kmphToMph.test.js: -------------------------------------------------------------------------------- 1 | const {kmphToMph} = require('./_30s.js'); 2 | 3 | test('kmphToMph is a Function', () => { 4 | expect(kmphToMph).toBeInstanceOf(Function); 5 | }); 6 | test('Returns mph from kph.', () => { 7 | expect(kmphToMph(10)).toBe(6.21371192); 8 | }); 9 | -------------------------------------------------------------------------------- /test/prefix.test.js: -------------------------------------------------------------------------------- 1 | const {prefix} = require('./_30s.js'); 2 | 3 | test('prefix is a Function', () => { 4 | expect(prefix).toBeInstanceOf(Function); 5 | }); 6 | test('prefix is a Function', () => { 7 | expect(typeof prefix('appearance')).toBe('string'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/sum.test.js: -------------------------------------------------------------------------------- 1 | const {sum} = require('./_30s.js'); 2 | 3 | test('sum is a Function', () => { 4 | expect(sum).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the sum of two or more numbers/arrays.', () => { 7 | expect(sum(...[1, 2, 3, 4])).toBe(10); 8 | }); 9 | -------------------------------------------------------------------------------- /test/timeTaken.test.js: -------------------------------------------------------------------------------- 1 | const {timeTaken} = require('./_30s.js'); 2 | 3 | test('timeTaken is a Function', () => { 4 | expect(timeTaken).toBeInstanceOf(Function); 5 | }); 6 | test('timeTaken is a Function', () => { 7 | expect(timeTaken(() => 10)).toBe(10); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Continuous-Integration.md: -------------------------------------------------------------------------------- 1 | ### Continuous Integration 2 | 3 | Continuous Integration (CI) is the practice of testing each change done to a codebase automatically and as early as possible. 4 | Two popular CI systems that integrate with GitHub are Travis CI and Circle CI. -------------------------------------------------------------------------------- /glossary/Currying.md: -------------------------------------------------------------------------------- 1 | ### Currying 2 | 3 | Currying is a way of constructing functions that allows partial application of a function's arguments. 4 | Practically, this means that a function is broken down into a series of functions, each one accepting part of the arguments. 5 | -------------------------------------------------------------------------------- /glossary/Selector.md: -------------------------------------------------------------------------------- 1 | ### Selector 2 | 3 | A CSS selector is a pattern that is used to select and/or style one or more elements in a document, based on certain rules. 4 | The order in which CSS selectors apply styles to elements is based on the rules of CSS specificity. 5 | -------------------------------------------------------------------------------- /test/isBrowser.test.js: -------------------------------------------------------------------------------- 1 | const {isBrowser} = require('./_30s.js'); 2 | 3 | test('isBrowser is a Function', () => { 4 | expect(isBrowser).toBeInstanceOf(Function); 5 | }); 6 | test('isBrowser is a Function', () => { 7 | expect(typeof isBrowser()).toBe('boolean'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/mphToKmph.test.js: -------------------------------------------------------------------------------- 1 | const {mphToKmph} = require('./_30s.js'); 2 | 3 | test('mphToKmph is a Function', () => { 4 | expect(mphToKmph).toBeInstanceOf(Function); 5 | }); 6 | test('Returns kph from mph.', () => { 7 | expect(mphToKmph(10)).toBe(16.09344000614692); 8 | }); 9 | -------------------------------------------------------------------------------- /test/sdbm.test.js: -------------------------------------------------------------------------------- 1 | const {sdbm} = require('./_30s.js'); 2 | 3 | test('sdbm is a Function', () => { 4 | expect(sdbm).toBeInstanceOf(Function); 5 | }); 6 | test('Hashes the input string into a whole number.', () => { 7 | expect(sdbm('name')).toBe(-3521204949); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Domain-name.md: -------------------------------------------------------------------------------- 1 | ### Domain name 2 | 3 | A domain name is a website's address on the Internet, used primarily in URLs to identify the server for each webpage. 4 | A domain name consists of a hierarchical sequence of names, separated by dots and ending with an extension. 5 | -------------------------------------------------------------------------------- /glossary/WebGL.md: -------------------------------------------------------------------------------- 1 | ### WebGL 2 | 3 | WebGL stands for Web Graphics Library and is a JavaScript API that can be used for drawing interactive 2D and 3D graphics. 4 | WebGL is based on OpenGL and can be invoked within HTML `` elements, which provide a rendering surface. 5 | -------------------------------------------------------------------------------- /test/call.test.js: -------------------------------------------------------------------------------- 1 | const {call} = require('./_30s.js'); 2 | 3 | test('call is a Function', () => { 4 | expect(call).toBeInstanceOf(Function); 5 | }); 6 | test('Calls function on given object', () => { 7 | expect(call('map', x => x * 2)([1, 2, 3])).toEqual([2, 4, 6]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/colorize.test.js: -------------------------------------------------------------------------------- 1 | const {colorize} = require('./_30s.js'); 2 | 3 | test('colorize is a Function', () => { 4 | expect(colorize).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the appropriate value', () => { 7 | expect(colorize('x').black).toBe('\x1b[30mx'); 8 | }); 9 | -------------------------------------------------------------------------------- /snippets/currentURL.md: -------------------------------------------------------------------------------- 1 | ### currentURL 2 | 3 | Returns the current URL. 4 | 5 | Use `window.location.href` to get current URL. 6 | 7 | ```js 8 | const currentURL = () => window.location.href; 9 | ``` 10 | 11 | ```js 12 | currentURL(); // 'https://google.com' 13 | ``` 14 | -------------------------------------------------------------------------------- /test/digitize.test.js: -------------------------------------------------------------------------------- 1 | const {digitize} = require('./_30s.js'); 2 | 3 | test('digitize is a Function', () => { 4 | expect(digitize).toBeInstanceOf(Function); 5 | }); 6 | test('Converts a number to an array of digits', () => { 7 | expect(digitize(123)).toEqual([1, 2, 3]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/heronArea.test.js: -------------------------------------------------------------------------------- 1 | const {heronArea} = require('./_30s.js'); 2 | 3 | test('heronArea is a Function', () => { 4 | expect(heronArea).toBeInstanceOf(Function); 5 | }); 6 | test('howManyTimes returns the correct result', () => { 7 | expect(heronArea(3, 4, 5)).toBe(6); 8 | }); 9 | -------------------------------------------------------------------------------- /test/isDivisible.test.js: -------------------------------------------------------------------------------- 1 | const {isDivisible} = require('./_30s.js'); 2 | 3 | test('isDivisible is a Function', () => { 4 | expect(isDivisible).toBeInstanceOf(Function); 5 | }); 6 | test('The number 6 is divisible by 3', () => { 7 | expect(isDivisible(6, 3)).toBeTruthy(); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/AJAX.md: -------------------------------------------------------------------------------- 1 | ### AJAX 2 | 3 | Asynchronous JavaScript and XML (known as AJAX) is a term that describes a new approach to using multiple technologies together in order to enable web applications to make quick updates to the user interface without reloading the entire browser page. 4 | -------------------------------------------------------------------------------- /glossary/Asynchronous-programming.md: -------------------------------------------------------------------------------- 1 | ### Asynchronous programming 2 | 3 | Asynchronous programming is a way to allow multiple events to trigger code without waiting for each other. 4 | The main benefits of asynchronous programming are improved application performance and responsiveness. 5 | -------------------------------------------------------------------------------- /glossary/CSS.md: -------------------------------------------------------------------------------- 1 | ### CSS 2 | 3 | CSS stands for Cascading Style Sheets and is a language used to style web pages. 4 | CSS documents are plaintext documents structured with rules, which consist of element selectors and property-value pairs that apply the styles to the specified selectors. 5 | -------------------------------------------------------------------------------- /glossary/Element.md: -------------------------------------------------------------------------------- 1 | ### Element 2 | 3 | A JavaScript representation of a DOM element commonly returned by `document.querySelector()` and `document.createElement()`. 4 | They are used when creating content with JavaScript for display in the DOM that needs to be programatically generated. 5 | -------------------------------------------------------------------------------- /glossary/Integration-testing.md: -------------------------------------------------------------------------------- 1 | ### Integration testing 2 | 3 | Integration testing is a type of software testing, used to test groups of units/components of a software. 4 | The purpose of integration tests are to validate that the units/components interact with each other as expected. 5 | -------------------------------------------------------------------------------- /glossary/JSON.md: -------------------------------------------------------------------------------- 1 | ### JSON 2 | 3 | JSON (JavaScript Object Notation) is a format for storing and exchanging data. 4 | It closely resembles the JavaScript object syntax, however some data types, such as dates and functions, cannot be natively represented and need to be serialized first. 5 | -------------------------------------------------------------------------------- /glossary/Mutabe-value.md: -------------------------------------------------------------------------------- 1 | ### Mutable value 2 | 3 | Mutable value is a type of variable that can be changed once created. 4 | Objects are mutable as their state can be modified after they are created. 5 | Primitive values are not mutable as we perform reassignment once we change them. 6 | -------------------------------------------------------------------------------- /glossary/Responsive-web-design.md: -------------------------------------------------------------------------------- 1 | ### Responsive web design 2 | 3 | Responsive web design is a web development concept aiming to provide optimal behavior and performance of websites on all web-enabled devices. 4 | Responsive web design is usually coupled with a mobile-first approach. 5 | -------------------------------------------------------------------------------- /glossary/Viewport.md: -------------------------------------------------------------------------------- 1 | ### Viewport 2 | 3 | A viewport is a polygonal (usually rectangular) area in computer graphics that is currently being viewed. 4 | In web development and design, it refers to the visible part of the document that is being viewed by the user in the browser window. 5 | -------------------------------------------------------------------------------- /snippets_archive/collatz.md: -------------------------------------------------------------------------------- 1 | ### collatz 2 | 3 | Applies the Collatz algorithm. 4 | 5 | If `n` is even, return `n/2`. Otherwise, return `3n+1`. 6 | 7 | ```js 8 | const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1); 9 | ``` 10 | 11 | ```js 12 | collatz(8); // 4 13 | ``` 14 | -------------------------------------------------------------------------------- /test/isSymbol.test.js: -------------------------------------------------------------------------------- 1 | const {isSymbol} = require('./_30s.js'); 2 | 3 | test('isSymbol is a Function', () => { 4 | expect(isSymbol).toBeInstanceOf(Function); 5 | }); 6 | test('Checks if the given argument is a symbol', () => { 7 | expect(isSymbol(Symbol('x'))).toBeTruthy(); 8 | }); 9 | -------------------------------------------------------------------------------- /test/isUndefined.test.js: -------------------------------------------------------------------------------- 1 | const {isUndefined} = require('./_30s.js'); 2 | 3 | test('isUndefined is a Function', () => { 4 | expect(isUndefined).toBeInstanceOf(Function); 5 | }); 6 | test('Returns true for undefined', () => { 7 | expect(isUndefined(undefined)).toBeTruthy(); 8 | }); 9 | -------------------------------------------------------------------------------- /test/reverseString.test.js: -------------------------------------------------------------------------------- 1 | const {reverseString} = require('./_30s.js'); 2 | 3 | test('reverseString is a Function', () => { 4 | expect(reverseString).toBeInstanceOf(Function); 5 | }); 6 | test('Reverses a string.', () => { 7 | expect(reverseString('foobar')).toBe('raboof'); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/API.md: -------------------------------------------------------------------------------- 1 | ### API 2 | 3 | API stands for Application Programming Interface and is a set of features and rules provided by a provided by a software to enable third-party software to interact with it. 4 | The code features of a web API usually include methods, properties, events or URLs. 5 | -------------------------------------------------------------------------------- /glossary/ES6.md: -------------------------------------------------------------------------------- 1 | ### ES6 2 | 3 | ES6 stands for ECMAScript 6 (also known as ECMAScript 2015), a version of the ECMAScript specification that standardizes JavaScript. 4 | ES6 adds a wide variety of new features to the specification, such as classes, promises, generators and arrow functions. 5 | -------------------------------------------------------------------------------- /glossary/Serialization.md: -------------------------------------------------------------------------------- 1 | ### Serialization 2 | 3 | Serialization is the process of converting an object or data structure into a format suitable for transfer over a network and/or storage. 4 | A common type of serialization in JavaScript is the conversion of an object into a JSON string. 5 | -------------------------------------------------------------------------------- /test/mapKeys.test.js: -------------------------------------------------------------------------------- 1 | const {mapKeys} = require('./_30s.js'); 2 | 3 | test('mapKeys is a Function', () => { 4 | expect(mapKeys).toBeInstanceOf(Function); 5 | }); 6 | test('Maps keys', () => { 7 | expect(mapKeys({ a: 1, b: 2 }, (val, key) => key + val)).toEqual({ a1: 1, b2: 2 }); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Continuous-Deployment.md: -------------------------------------------------------------------------------- 1 | ### Continuous Deployment 2 | 3 | Continuous Deployment follows the testing that happens during Continuous Integration and pushes changes to a staging or production system. 4 | Continuous Deployment ensures that a version of the codebase is accessible at all times. -------------------------------------------------------------------------------- /test/initial.test.js: -------------------------------------------------------------------------------- 1 | const {initial} = require('./_30s.js'); 2 | 3 | test('initial is a Function', () => { 4 | expect(initial).toBeInstanceOf(Function); 5 | }); 6 | test('Returns all the elements of an array except the last one', () => { 7 | expect(initial([1, 2, 3])).toEqual([1, 2]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/mapNumRange.test.js: -------------------------------------------------------------------------------- 1 | const {mapNumRange} = require('./_30s.js'); 2 | 3 | test('mapNumRange is a Function', () => { 4 | expect(mapNumRange).toBeInstanceOf(Function); 5 | }); 6 | test('Maps 5 to the range 0-100 from 0-10', () => { 7 | expect(mapNumRange(5,0,10,0,100)).toEqual(50); 8 | }); 9 | -------------------------------------------------------------------------------- /test/radsToDegrees.test.js: -------------------------------------------------------------------------------- 1 | const {radsToDegrees} = require('./_30s.js'); 2 | 3 | test('radsToDegrees is a Function', () => { 4 | expect(radsToDegrees).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the appropriate value', () => { 7 | expect(radsToDegrees(Math.PI / 2)).toBe(90); 8 | }); 9 | -------------------------------------------------------------------------------- /test/unary.test.js: -------------------------------------------------------------------------------- 1 | const {unary} = require('./_30s.js'); 2 | 3 | test('unary is a Function', () => { 4 | expect(unary).toBeInstanceOf(Function); 5 | }); 6 | test('Discards arguments after the first one', () => { 7 | expect(['6', '8', '10'].map(unary(parseInt))).toEqual([6, 8, 10]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/unionBy.test.js: -------------------------------------------------------------------------------- 1 | const {unionBy} = require('./_30s.js'); 2 | 3 | test('unionBy is a Function', () => { 4 | expect(unionBy).toBeInstanceOf(Function); 5 | }); 6 | test('Produces the appropriate results', () => { 7 | expect(unionBy([2.1], [1.2, 2.3], Math.floor)).toEqual([2.1, 1.2]); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Domain-name-registrar.md: -------------------------------------------------------------------------------- 1 | ### Domain name registrar 2 | 3 | A domain name registrar is a company that manages the reservation of internet domain names. 4 | A domain name registrar must be approved by a general top-level domain (gTLD) registry or a country code top-level domain (ccTLD) registry. 5 | -------------------------------------------------------------------------------- /glossary/WebAssembly.md: -------------------------------------------------------------------------------- 1 | ### WebAssembly 2 | 3 | WebAssembly (WA) is a web standard that defines an assembly-like text format and corresponding binary format for executalbe code in web pages. 4 | WebAssembly is meant to complement JavaScript and improve its performance to match native code performance. 5 | -------------------------------------------------------------------------------- /snippet-template.md: -------------------------------------------------------------------------------- 1 | ### functionName 2 | 3 | Explain briefly what the snippet does. 4 | 5 | Explain briefly how the snippet works. 6 | 7 | ```js 8 | const functionName = arguments => 9 | {functionBody} 10 | ``` 11 | 12 | ```js 13 | functionName('sampleInput'); // 'sampleOutput' 14 | ``` 15 | -------------------------------------------------------------------------------- /test/RGBToHex.test.js: -------------------------------------------------------------------------------- 1 | const {RGBToHex} = require('./_30s.js'); 2 | 3 | test('RGBToHex is a Function', () => { 4 | expect(RGBToHex).toBeInstanceOf(Function); 5 | }); 6 | test('Converts the values of RGB components to a color code.', () => { 7 | expect(RGBToHex(255, 165, 1)).toBe('ffa501'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/bottomVisible.test.js: -------------------------------------------------------------------------------- 1 | const {bottomVisible} = require('./_30s.js'); 2 | 3 | test('bottomVisible is a Function', () => { 4 | expect(bottomVisible).toBeInstanceOf(Function); 5 | }); 6 | test('bottomVisible returns a boolean', () => { 7 | expect(typeof bottomVisible()).toBe('boolean'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/currentURL.test.js: -------------------------------------------------------------------------------- 1 | const {currentURL} = require('./_30s.js'); 2 | 3 | test('currentURL is a Function', () => { 4 | expect(currentURL).toBeInstanceOf(Function); 5 | }); 6 | test('currentURL returns the appropriate value', () => { 7 | expect(currentURL()).toEqual(global.location.href); 8 | }); 9 | -------------------------------------------------------------------------------- /test/negate.test.js: -------------------------------------------------------------------------------- 1 | const {negate} = require('./_30s.js'); 2 | 3 | test('negate is a Function', () => { 4 | expect(negate).toBeInstanceOf(Function); 5 | }); 6 | test('Negates a predicate function', () => { 7 | expect([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0))).toEqual([1, 3, 5]); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Deserialization.md: -------------------------------------------------------------------------------- 1 | ### Deserialization 2 | 3 | Deserialization is the process of converting a format that has been transferred over a network and/or used for storage to an object or data structure. 4 | A common type of deserialization in JavaScript is the conversion of JSON string into an object. 5 | -------------------------------------------------------------------------------- /glossary/First-class-function.md: -------------------------------------------------------------------------------- 1 | ### First-class function 2 | 3 | A programming language is said to have first-class functions if it treats them as first-class citizens, meaning they can be passed as arguments, be returned as values from other functions, be assigned to variables and stored in data structures. -------------------------------------------------------------------------------- /glossary/Object.md: -------------------------------------------------------------------------------- 1 | ### Object 2 | 3 | Objects are data structures that contain data and instructions for working with the data. 4 | Objects consist of key-value pairs, where the keys are alphanumeric identifiers and the values can either be primitives or objects. 5 | JavaScript functions are also objects. 6 | -------------------------------------------------------------------------------- /test/deepFlatten.test.js: -------------------------------------------------------------------------------- 1 | const {deepFlatten} = require('./_30s.js'); 2 | 3 | test('deepFlatten is a Function', () => { 4 | expect(deepFlatten).toBeInstanceOf(Function); 5 | }); 6 | test('Deep flattens an array', () => { 7 | expect(deepFlatten([1, [2], [[3], 4], 5])).toEqual([1, 2, 3, 4, 5]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/difference.test.js: -------------------------------------------------------------------------------- 1 | const {difference} = require('./_30s.js'); 2 | 3 | test('difference is a Function', () => { 4 | expect(difference).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the difference between two arrays', () => { 7 | expect(difference([1, 2, 3], [1, 2, 4])).toEqual([3]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/distance.test.js: -------------------------------------------------------------------------------- 1 | const {distance} = require('./_30s.js'); 2 | 3 | test('distance is a Function', () => { 4 | expect(distance).toBeInstanceOf(Function); 5 | }); 6 | test('Calculates the distance between two points', () => { 7 | expect(distance(1, 1, 2, 3)).toBeCloseTo(2.23606797749979, 5); 8 | }); 9 | -------------------------------------------------------------------------------- /test/fibonacci.test.js: -------------------------------------------------------------------------------- 1 | const {fibonacci} = require('./_30s.js'); 2 | 3 | test('fibonacci is a Function', () => { 4 | expect(fibonacci).toBeInstanceOf(Function); 5 | }); 6 | test('Generates an array, containing the Fibonacci sequence', () => { 7 | expect(fibonacci(6)).toEqual([0, 1, 1, 2, 3, 5]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/hammingDistance.test.js: -------------------------------------------------------------------------------- 1 | const {hammingDistance} = require('./_30s.js'); 2 | 3 | test('hammingDistance is a Function', () => { 4 | expect(hammingDistance).toBeInstanceOf(Function); 5 | }); 6 | test('retuns hamming disance between 2 values', () => { 7 | expect(hammingDistance(2, 3)).toBe(1); 8 | }); 9 | -------------------------------------------------------------------------------- /test/powerset.test.js: -------------------------------------------------------------------------------- 1 | const {powerset} = require('./_30s.js'); 2 | 3 | test('powerset is a Function', () => { 4 | expect(powerset).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the powerset of a given array of numbers.', () => { 7 | expect(powerset([1, 2])).toEqual([[], [1], [2], [2, 1]]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/primes.test.js: -------------------------------------------------------------------------------- 1 | const {primes} = require('./_30s.js'); 2 | 3 | test('primes is a Function', () => { 4 | expect(primes).toBeInstanceOf(Function); 5 | }); 6 | test('Generates primes up to a given number, using the Sieve of Eratosthenes.', () => { 7 | expect(primes(10)).toEqual([2, 3, 5, 7]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/serializeCookie.test.js: -------------------------------------------------------------------------------- 1 | const {serializeCookie} = require('./_30s.js'); 2 | 3 | test('serializeCookie is a Function', () => { 4 | expect(serializeCookie).toBeInstanceOf(Function); 5 | }); 6 | test('Serializes the cookie', () => { 7 | expect(serializeCookie('foo', 'bar')).toBe('foo=bar'); 8 | }); 9 | -------------------------------------------------------------------------------- /snippets/isSymbol.md: -------------------------------------------------------------------------------- 1 | ### isSymbol 2 | 3 | Checks if the given argument is a symbol. 4 | 5 | Use `typeof` to check if a value is classified as a symbol primitive. 6 | 7 | ```js 8 | const isSymbol = val => typeof val === 'symbol'; 9 | ``` 10 | 11 | ```js 12 | isSymbol(Symbol('x')); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /test/coalesce.test.js: -------------------------------------------------------------------------------- 1 | const {coalesce} = require('./_30s.js'); 2 | 3 | test('coalesce is a Function', () => { 4 | expect(coalesce).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the first non-null/undefined argument', () => { 7 | expect(coalesce(null, undefined, '', NaN, 'Waldo')).toEqual(''); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/SQL.md: -------------------------------------------------------------------------------- 1 | ### SQL 2 | 3 | SQL stands for Structured Query Language and is a language used to create, update, retrieve and calculate data in table-based databases. 4 | SQL databases use a relational database model and are particularly useful in handlind structured data with relations between different entities. 5 | -------------------------------------------------------------------------------- /test/escapeRegExp.test.js: -------------------------------------------------------------------------------- 1 | const {escapeRegExp} = require('./_30s.js'); 2 | 3 | test('escapeRegExp is a Function', () => { 4 | expect(escapeRegExp).toBeInstanceOf(Function); 5 | }); 6 | test('Escapes a string to use in a regular expression', () => { 7 | expect(escapeRegExp('(test)')).toBe('\\(test\\)'); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/PWA.md: -------------------------------------------------------------------------------- 1 | ### PWA 2 | 3 | Progressive Web App (known as PWA) is a term used to describe web applications that load like regular websites but can offer the user functionality such as working offline, push notifications, and device hardware access that were traditionally available only to native mobile applications. 4 | -------------------------------------------------------------------------------- /test/findLast.test.js: -------------------------------------------------------------------------------- 1 | const {findLast} = require('./_30s.js'); 2 | 3 | test('findLast is a Function', () => { 4 | expect(findLast).toBeInstanceOf(Function); 5 | }); 6 | test('Finds last element for which the given function returns true', () => { 7 | expect(findLast([1, 2, 3, 4], n => n % 2 === 1)).toBe(3); 8 | }); 9 | -------------------------------------------------------------------------------- /test/similarity.test.js: -------------------------------------------------------------------------------- 1 | const {similarity} = require('./_30s.js'); 2 | 3 | test('similarity is a Function', () => { 4 | expect(similarity).toBeInstanceOf(Function); 5 | }); 6 | test('Returns an array of elements that appear in both arrays.', () => { 7 | expect(similarity([1, 2, 3], [1, 2, 4])).toEqual([1, 2]); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Cross-site-scripting-xss.md: -------------------------------------------------------------------------------- 1 | ### Cross-site scripting (XSS) 2 | 3 | XSS refers to client-side code injection where the attacker injects malicious scripts into a legitimate website or web application. 4 | This is often achieved when the application does not validate user input and freely injects dynamic HTML content. 5 | -------------------------------------------------------------------------------- /test/fibonacciCountUntilNum.test.js: -------------------------------------------------------------------------------- 1 | const {fibonacciCountUntilNum} = require('./_30s.js'); 2 | 3 | test('fibonacciCountUntilNum is a Function', () => { 4 | expect(fibonacciCountUntilNum).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the correct number', () => { 7 | expect(fibonacciCountUntilNum(10)).toBe(7); 8 | }); 9 | -------------------------------------------------------------------------------- /test/fibonacciUntilNum.test.js: -------------------------------------------------------------------------------- 1 | const {fibonacciUntilNum} = require('./_30s.js'); 2 | 3 | test('fibonacciUntilNum is a Function', () => { 4 | expect(fibonacciUntilNum).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the correct sequence', () => { 7 | expect(fibonacciUntilNum(10)).toEqual([0, 1, 1, 2, 3, 5, 8]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/omit.test.js: -------------------------------------------------------------------------------- 1 | const {omit} = require('./_30s.js'); 2 | 3 | test('omit is a Function', () => { 4 | expect(omit).toBeInstanceOf(Function); 5 | }); 6 | test('Omits the key-value pairs corresponding to the given keys from an object', () => { 7 | expect(omit({ a: 1, b: '2', c: 3 }, ['b'])).toEqual({ a: 1, c: 3 }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/parseCookie.test.js: -------------------------------------------------------------------------------- 1 | const {parseCookie} = require('./_30s.js'); 2 | 3 | test('parseCookie is a Function', () => { 4 | expect(parseCookie).toBeInstanceOf(Function); 5 | }); 6 | test('Parses the cookie', () => { 7 | expect(parseCookie('foo=bar; equation=E%3Dmc%5E2')).toEqual({ foo: 'bar', equation: 'E=mc^2' }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/removeNonASCII.test.js: -------------------------------------------------------------------------------- 1 | const {removeNonASCII} = require('./_30s.js'); 2 | 3 | test('removeNonASCII is a Function', () => { 4 | expect(removeNonASCII).toBeInstanceOf(Function); 5 | }); 6 | test('Removes non-ASCII characters', () => { 7 | expect(removeNonASCII('äÄçÇéÉêlorem-ipsumöÖÐþúÚ')).toBe('lorem-ipsum'); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Functor.md: -------------------------------------------------------------------------------- 1 | ### Functor 2 | 3 | A Functor is a data type common in functional programming that implements a `map` method. 4 | The `map` method takes a function and applies it to the data in the Functor, returning a new instance of the Functor with the result. 5 | JavaScript `Array`s are an example of the Functor data type. 6 | -------------------------------------------------------------------------------- /snippets/isNull.md: -------------------------------------------------------------------------------- 1 | ### isNull 2 | 3 | Returns `true` if the specified value is `null`, `false` otherwise. 4 | 5 | Use the strict equality operator to check if the value and of `val` are equal to `null`. 6 | 7 | ```js 8 | const isNull = val => val === null; 9 | ``` 10 | 11 | ```js 12 | isNull(null); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /test/clampNumber.test.js: -------------------------------------------------------------------------------- 1 | const {clampNumber} = require('./_30s.js'); 2 | 3 | test('clampNumber is a Function', () => { 4 | expect(clampNumber).toBeInstanceOf(Function); 5 | }); 6 | test('Clamps num within the inclusive range specified by the boundary values a and b', () => { 7 | expect(clampNumber(2, 3, 5)).toBe(3); 8 | }); 9 | -------------------------------------------------------------------------------- /test/cloneRegExp.test.js: -------------------------------------------------------------------------------- 1 | const {cloneRegExp} = require('./_30s.js'); 2 | 3 | test('cloneRegExp is a Function', () => { 4 | expect(cloneRegExp).toBeInstanceOf(Function); 5 | }); 6 | const rgTest = /./g; 7 | test('Clones regular expressions properly', () => { 8 | expect(cloneRegExp(rgTest)).not.toBe(rgTest); 9 | }); 10 | -------------------------------------------------------------------------------- /test/defaults.test.js: -------------------------------------------------------------------------------- 1 | const {defaults} = require('./_30s.js'); 2 | 3 | test('defaults is a Function', () => { 4 | expect(defaults).toBeInstanceOf(Function); 5 | }); 6 | test('Assigns default values for undefined properties', () => { 7 | expect(defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 })).toEqual({ a: 1, b: 2 }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/intersection.test.js: -------------------------------------------------------------------------------- 1 | const {intersection} = require('./_30s.js'); 2 | 3 | test('intersection is a Function', () => { 4 | expect(intersection).toBeInstanceOf(Function); 5 | }); 6 | test('Returns a list of elements that exist in both arrays', () => { 7 | expect(intersection([1, 2, 3], [4, 3, 2])).toEqual([2, 3]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/isBrowserTabFocused.test.js: -------------------------------------------------------------------------------- 1 | const {isBrowserTabFocused} = require('./_30s.js'); 2 | 3 | test('isBrowserTabFocused is a Function', () => { 4 | expect(isBrowserTabFocused).toBeInstanceOf(Function); 5 | }); 6 | test('isBrowserTabFocused is a Function', () => { 7 | expect(typeof isBrowserTabFocused()).toBe('boolean'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/pick.test.js: -------------------------------------------------------------------------------- 1 | const {pick} = require('./_30s.js'); 2 | 3 | test('pick is a Function', () => { 4 | expect(pick).toBeInstanceOf(Function); 5 | }); 6 | test('Picks the key-value pairs corresponding to the given keys from an object.', () => { 7 | expect(pick({ a: 1, b: '2', c: 3 }, ['a', 'c'])).toEqual({ a: 1, c: 3 }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/remove.test.js: -------------------------------------------------------------------------------- 1 | const {remove} = require('./_30s.js'); 2 | 3 | test('remove is a Function', () => { 4 | expect(remove).toBeInstanceOf(Function); 5 | }); 6 | test('Removes elements from an array for which the given function returns false', () => { 7 | expect(remove([1, 2, 3, 4], n => n % 2 === 0)).toEqual([2, 4]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/tail.test.js: -------------------------------------------------------------------------------- 1 | const {tail} = require('./_30s.js'); 2 | 3 | test('tail is a Function', () => { 4 | expect(tail).toBeInstanceOf(Function); 5 | }); 6 | test('Returns tail', () => { 7 | expect(tail([1, 2, 3])).toEqual([2, 3]); 8 | }); 9 | test('Returns tail', () => { 10 | expect(tail([1])).toEqual([1]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/times.test.js: -------------------------------------------------------------------------------- 1 | const {times} = require('./_30s.js'); 2 | 3 | test('times is a Function', () => { 4 | expect(times).toBeInstanceOf(Function); 5 | }); 6 | var output = ''; 7 | times(5, i => (output += i)); 8 | test('Runs a function the specified amount of times', () => { 9 | expect(output).toBe('01234'); 10 | }); 11 | -------------------------------------------------------------------------------- /test/truncateString.test.js: -------------------------------------------------------------------------------- 1 | const {truncateString} = require('./_30s.js'); 2 | 3 | test('truncateString is a Function', () => { 4 | expect(truncateString).toBeInstanceOf(Function); 5 | }); 6 | test('Truncates a "boomerang" up to a specified length.', () => { 7 | expect(truncateString('boomerang', 7)).toBe('boom...'); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/Object-oriented-programming.md: -------------------------------------------------------------------------------- 1 | ### Object-oriented programming 2 | 3 | Object-oriented programming (OOP) is a programming paradigm based on the concept of objects, which may contain both data and procedures which can be use to operate on them. 4 | JavaScript supports Object-oriented programming both via prototypes and classes. 5 | -------------------------------------------------------------------------------- /glossary/Prepared-statements.md: -------------------------------------------------------------------------------- 1 | ### Prepared statements 2 | 3 | In databases management systems, prepared statements are templates that can be used to execute queries with the provided values substituting the template's parameters. 4 | Prepared statements offer many benefits, such as reusability, maintainability and higher security. 5 | -------------------------------------------------------------------------------- /glossary/Promise.md: -------------------------------------------------------------------------------- 1 | ### Promise 2 | 3 | The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value. 4 | A Promise can be in one of these states: pending(initial state, neither fulfilled nor rejected), fulfilled(operation completed successfully), rejected(operation failed). 5 | -------------------------------------------------------------------------------- /glossary/Prototype-based-programming.md: -------------------------------------------------------------------------------- 1 | ### Prototype-based programming 2 | 3 | Prototype-based programming is a style of object-oriented programming, where inheritance is based on object delegation, reusing objects that serve as prototypes. 4 | Prototype-based programming allows the creation of objects before defining their classes. 5 | -------------------------------------------------------------------------------- /snippets/isString.md: -------------------------------------------------------------------------------- 1 | ### isString 2 | 3 | Checks if the given argument is a string. Only works for string primitives. 4 | 5 | Use `typeof` to check if a value is classified as a string primitive. 6 | 7 | ```js 8 | const isString = val => typeof val === 'string'; 9 | ``` 10 | 11 | ```js 12 | isString('10'); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets_archive/celsiusToFahrenheit.md: -------------------------------------------------------------------------------- 1 | ### celsiusToFahrenheit 2 | 3 | Celsius to Fahrenheit temperature conversion. 4 | 5 | Follows the conversion formula `F = 1.8C + 32`. 6 | 7 | ```js 8 | const celsiusToFahrenheit = degrees => 1.8 * degrees + 32; 9 | ``` 10 | 11 | ```js 12 | celsiusToFahrenheit(33) // 91.4 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets_archive/fahrenheitToCelsius.md: -------------------------------------------------------------------------------- 1 | ### fahrenheitToCelsius 2 | 3 | Fahrenheit to Celsius temperature conversion. 4 | 5 | Follows the conversion formula `C = (F - 32) * 5/9`. 6 | 7 | ```js 8 | const fahrenheitToCelsius = degrees => (degrees - 32) * 5/9; 9 | ``` 10 | 11 | ```js 12 | fahrenheitToCelsius(32); // 0 13 | ``` 14 | -------------------------------------------------------------------------------- /test/dropWhile.test.js: -------------------------------------------------------------------------------- 1 | const {dropWhile} = require('./_30s.js'); 2 | 3 | test('dropWhile is a Function', () => { 4 | expect(dropWhile).toBeInstanceOf(Function); 5 | }); 6 | test('Removes elements in an array until the passed function returns true.', () => { 7 | expect(dropWhile([1, 2, 3, 4], n => n >= 3)).toEqual([3, 4]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/over.test.js: -------------------------------------------------------------------------------- 1 | const {over} = require('./_30s.js'); 2 | 3 | test('over is a Function', () => { 4 | expect(over).toBeInstanceOf(Function); 5 | }); 6 | const minMax = over(Math.min, Math.max); 7 | test('Applies given functions over multiple arguments', () => { 8 | expect(minMax(1, 2, 3, 4, 5)).toEqual([1, 5]); 9 | }); 10 | -------------------------------------------------------------------------------- /test/pull.test.js: -------------------------------------------------------------------------------- 1 | const {pull} = require('./_30s.js'); 2 | 3 | test('pull is a Function', () => { 4 | expect(pull).toBeInstanceOf(Function); 5 | }); 6 | let myArray = ['a', 'b', 'c', 'a', 'b', 'c']; 7 | pull(myArray, 'a', 'c'); 8 | test('Pulls the specified values', () => { 9 | expect(myArray).toEqual(['b', 'b']); 10 | }); 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | ## Description 8 | 9 | 10 | -------------------------------------------------------------------------------- /glossary/MVC.md: -------------------------------------------------------------------------------- 1 | ### MVC 2 | 3 | MVC stands for Model-View-Controller and is a software design pattern, emphasizing separation of concerns (logic and display). 4 | The Model part of the MVC pattern refers to the data and business logic, the View handles the layout and display, while the Controller routes commands to the model and view parts. 5 | -------------------------------------------------------------------------------- /snippets/distance.md: -------------------------------------------------------------------------------- 1 | ### distance 2 | 3 | Returns the distance between two points. 4 | 5 | Use `Math.hypot()` to calculate the Euclidean distance between two points. 6 | 7 | ```js 8 | const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0); 9 | ``` 10 | 11 | ```js 12 | distance(1, 1, 2, 3); // 2.23606797749979 13 | ``` 14 | -------------------------------------------------------------------------------- /test/findLastIndex.test.js: -------------------------------------------------------------------------------- 1 | const {findLastIndex} = require('./_30s.js'); 2 | 3 | test('findLastIndex is a Function', () => { 4 | expect(findLastIndex).toBeInstanceOf(Function); 5 | }); 6 | test('Finds last index for which the given function returns true', () => { 7 | expect(findLastIndex([1, 2, 3, 4], n => n % 2 === 1)).toBe(2); 8 | }); 9 | -------------------------------------------------------------------------------- /test/isEven.test.js: -------------------------------------------------------------------------------- 1 | const {isEven} = require('./_30s.js'); 2 | 3 | test('isEven is a Function', () => { 4 | expect(isEven).toBeInstanceOf(Function); 5 | }); 6 | test('4 is even number', () => { 7 | expect(isEven(4)).toBeTruthy(); 8 | }); 9 | test('5 is not an even number', () => { 10 | expect(isEven(5)).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/nodeListToArray.test.js: -------------------------------------------------------------------------------- 1 | const {nodeListToArray} = require('./_30s.js'); 2 | 3 | test('nodeListToArray is a Function', () => { 4 | expect(nodeListToArray).toBeInstanceOf(Function); 5 | }); 6 | test('nodeListToArray returns an array of proper length', () => { 7 | expect(nodeListToArray(document.childNodes).length).toBe(2); 8 | }); 9 | -------------------------------------------------------------------------------- /test/takeRightWhile.test.js: -------------------------------------------------------------------------------- 1 | const {takeRightWhile} = require('./_30s.js'); 2 | 3 | test('takeRightWhile is a Function', () => { 4 | expect(takeRightWhile).toBeInstanceOf(Function); 5 | }); 6 | test('Removes elements until the function returns true', () => { 7 | expect(takeRightWhile([1, 2, 3, 4], n => n < 3)).toEqual([3, 4]); 8 | }); 9 | -------------------------------------------------------------------------------- /snippets/escapeRegExp.md: -------------------------------------------------------------------------------- 1 | ### escapeRegExp 2 | 3 | Escapes a string to use in a regular expression. 4 | 5 | Use `String.prototype.replace()` to escape special characters. 6 | 7 | ```js 8 | const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); 9 | ``` 10 | 11 | ```js 12 | escapeRegExp('(test)'); // \\(test\\) 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets_archive/pipeLog.md: -------------------------------------------------------------------------------- 1 | ### pipeLog 2 | 3 | Logs a value and returns it. 4 | 5 | Use `console.log` to log the supplied value, combined with the `||` operator to return it. 6 | 7 | 8 | 9 | ```js 10 | const pipeLog = data => console.log(data) || data; 11 | ``` 12 | 13 | ```js 14 | pipeLog(1); // logs `1` and returns `1` 15 | ``` 16 | -------------------------------------------------------------------------------- /test/objectToPairs.test.js: -------------------------------------------------------------------------------- 1 | const {objectToPairs} = require('./_30s.js'); 2 | 3 | test('objectToPairs is a Function', () => { 4 | expect(objectToPairs).toBeInstanceOf(Function); 5 | }); 6 | test('Creates an array of key-value pair arrays from an object.', () => { 7 | expect(objectToPairs({ a: 1, b: 2 })).toEqual([['a', 1], ['b', 2]]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/toDecimalMark.test.js: -------------------------------------------------------------------------------- 1 | const {toDecimalMark} = require('./_30s.js'); 2 | 3 | test('toDecimalMark is a Function', () => { 4 | expect(toDecimalMark).toBeInstanceOf(Function); 5 | }); 6 | test('convert a float-point arithmetic to the Decimal mark form', () => { 7 | expect(toDecimalMark(12305030388.9087)).toBe('12,305,030,388.909'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/xProd.test.js: -------------------------------------------------------------------------------- 1 | const {xProd} = require('./_30s.js'); 2 | 3 | test('xProd is a Function', () => { 4 | expect(xProd).toBeInstanceOf(Function); 5 | }); 6 | test("xProd([1, 2], ['a', 'b']) returns [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]", () => { 7 | expect(xProd([1, 2], ['a', 'b'])).toEqual([[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]); 8 | }); 9 | -------------------------------------------------------------------------------- /glossary/WebComponents.md: -------------------------------------------------------------------------------- 1 | ### Web Components 2 | 3 | Web Components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use on web pages and apps. 4 | Building custom components using these standards means that you can use them across modern browsers regardless of any JavaScript library or framework. 5 | -------------------------------------------------------------------------------- /snippets/degreesToRads.md: -------------------------------------------------------------------------------- 1 | ### degreesToRads 2 | 3 | Converts an angle from degrees to radians. 4 | 5 | Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians. 6 | 7 | ```js 8 | const degreesToRads = deg => (deg * Math.PI) / 180.0; 9 | ``` 10 | 11 | ```js 12 | degreesToRads(90.0); // ~1.5708 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/head.md: -------------------------------------------------------------------------------- 1 | ### head 2 | 3 | ------------ 4 | 5 | Returns the head of a list. 6 | 7 | Use to return the first element of the passed array. 8 | 9 | ------------ 10 | 11 | 返回数组的第一个元素。 12 | 13 | 使用 `arr[0]` 返回传递数组的第一个元素。 14 | 15 | ```js 16 | const head = arr => arr[0]; 17 | ``` 18 | 19 | ```js 20 | head([1, 2, 3]); // 1 21 | ``` 22 | -------------------------------------------------------------------------------- /snippets/isFunction.md: -------------------------------------------------------------------------------- 1 | ### isFunction 2 | 3 | Checks if the given argument is a function. 4 | 5 | Use `typeof` to check if a value is classified as a function primitive. 6 | 7 | ```js 8 | const isFunction = val => typeof val === 'function'; 9 | ``` 10 | 11 | ```js 12 | isFunction('x'); // false 13 | isFunction(x => x); // true 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/negate.md: -------------------------------------------------------------------------------- 1 | ### negate 2 | 3 | Negates a predicate function. 4 | 5 | Take a predicate function and apply the not operator (`!`) to it with its arguments. 6 | 7 | ```js 8 | const negate = func => (...args) => !func(...args); 9 | ``` 10 | 11 | ```js 12 | [1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)); // [ 1, 3, 5 ] 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/radsToDegrees.md: -------------------------------------------------------------------------------- 1 | ### radsToDegrees 2 | 3 | Converts an angle from radians to degrees. 4 | 5 | Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees. 6 | 7 | ```js 8 | const radsToDegrees = rad => (rad * 180.0) / Math.PI; 9 | ``` 10 | 11 | ```js 12 | radsToDegrees(Math.PI / 2); // 90 13 | ``` 14 | -------------------------------------------------------------------------------- /test/atob.test.js: -------------------------------------------------------------------------------- 1 | const {atob} = require('./_30s.js'); 2 | 3 | test('atob is a Function', () => { 4 | expect(atob).toBeInstanceOf(Function); 5 | }); 6 | test('atob("Zm9vYmFy") equals "foobar"', () => { 7 | expect(atob('Zm9vYmFy')).toBe('foobar'); 8 | }); 9 | test('atob("Z") returns ""', () => { 10 | expect(atob('Z')).toBe(''); 11 | }); 12 | -------------------------------------------------------------------------------- /test/debounce.test.js: -------------------------------------------------------------------------------- 1 | const {debounce} = require('./_30s.js'); 2 | 3 | test('debounce is a Function', () => { 4 | expect(debounce).toBeInstanceOf(Function); 5 | }); 6 | test('Works as expected', done => { 7 | const debouncedFn = debounce(() => { 8 | expect(true).toBeTruthy(); 9 | done(); 10 | }); 11 | debouncedFn(); 12 | }); 13 | -------------------------------------------------------------------------------- /test/hz.test.js: -------------------------------------------------------------------------------- 1 | const {hz} = require('./_30s.js'); 2 | 3 | test('hz is a Function', () => { 4 | expect(hz).toBeInstanceOf(Function); 5 | }); 6 | test('hz returns a number', () => { 7 | expect(typeof hz(x => x)).toBe('number'); 8 | }); 9 | test('hz returns a number', () => { 10 | expect(typeof hz(x => x, 10)).toBe('number'); 11 | }); 12 | -------------------------------------------------------------------------------- /test/objectFromPairs.test.js: -------------------------------------------------------------------------------- 1 | const {objectFromPairs} = require('./_30s.js'); 2 | 3 | test('objectFromPairs is a Function', () => { 4 | expect(objectFromPairs).toBeInstanceOf(Function); 5 | }); 6 | test('Creates an object from the given key-value pairs.', () => { 7 | expect(objectFromPairs([['a', 1], ['b', 2]])).toEqual({ a: 1, b: 2 }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/vectorDistance.test.js: -------------------------------------------------------------------------------- 1 | const { vectorDistance } = require('./_30s.js'); 2 | 3 | test('vectorDistance is a Function', () => { 4 | expect(vectorDistance).toBeInstanceOf(Function); 5 | }); 6 | test('Calculates the distance between two vectors', () => { 7 | expect(vectorDistance(10, 0, 5, 20, 0, 10)).toBeCloseTo(11.180339887498949, 5); 8 | }); 9 | -------------------------------------------------------------------------------- /snippets/isBoolean.md: -------------------------------------------------------------------------------- 1 | ### isBoolean 2 | 3 | Checks if the given argument is a native boolean element. 4 | 5 | Use `typeof` to check if a value is classified as a boolean primitive. 6 | 7 | ```js 8 | const isBoolean = val => typeof val === 'boolean'; 9 | ``` 10 | 11 | ```js 12 | isBoolean(null); // false 13 | isBoolean(false); // true 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets_archive/kmphToMph.md: -------------------------------------------------------------------------------- 1 | ### kmphToMph 2 | 3 | Convert kilometers/hour to miles/hour. 4 | 5 | Multiply the constant of proportionality with the argument. 6 | 7 | ```js 8 | const kmphToMph = (kmph) => 0.621371192 * kmph; 9 | ``` 10 | 11 | ```js 12 | kmphToMph(10); // 16.09344000614692 13 | kmphToMph(345.4); // 138.24264965280207 14 | ``` 15 | -------------------------------------------------------------------------------- /test/ary.test.js: -------------------------------------------------------------------------------- 1 | const {ary} = require('./_30s.js'); 2 | 3 | test('ary is a Function', () => { 4 | expect(ary).toBeInstanceOf(Function); 5 | }); 6 | const firstTwoMax = ary(Math.max, 2); 7 | test('Discards arguments with index >=n', () => { 8 | expect([[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x))).toEqual([6, 8, 10]); 9 | }); 10 | -------------------------------------------------------------------------------- /test/forOwn.test.js: -------------------------------------------------------------------------------- 1 | const {forOwn} = require('./_30s.js'); 2 | 3 | test('forOwn is a Function', () => { 4 | expect(forOwn).toBeInstanceOf(Function); 5 | }); 6 | let output = []; 7 | forOwn({ foo: 'bar', a: 1 }, v => output.push(v)); 8 | test("Iterates over an element's key-value pairs", () => { 9 | expect(output).toEqual(['bar', 1]); 10 | }); 11 | -------------------------------------------------------------------------------- /test/isNull.test.js: -------------------------------------------------------------------------------- 1 | const {isNull} = require('./_30s.js'); 2 | 3 | test('isNull is a Function', () => { 4 | expect(isNull).toBeInstanceOf(Function); 5 | }); 6 | test('passed argument is a null', () => { 7 | expect(isNull(null)).toBeTruthy(); 8 | }); 9 | test('passed argument is a null', () => { 10 | expect(isNull(NaN)).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/unflattenObject.test.js: -------------------------------------------------------------------------------- 1 | const {unflattenObject} = require('./_30s.js'); 2 | 3 | test('unflattenObject is a Function', () => { 4 | expect(unflattenObject).toBeInstanceOf(Function); 5 | }); 6 | test('Unflattens an object with the paths for keys', () => { 7 | expect(unflattenObject({ 'a.b.c': 1, d: 1 })).toEqual({ a: { b: { c: 1 } }, d: 1 }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/unfold.test.js: -------------------------------------------------------------------------------- 1 | const {unfold} = require('./_30s.js'); 2 | 3 | test('unfold is a Function', () => { 4 | expect(unfold).toBeInstanceOf(Function); 5 | }); 6 | var f = n => (n > 50 ? false : [-n, n + 10]); 7 | test('Works with a given function, producing an array', () => { 8 | expect(unfold(f, 10)).toEqual([-10, -20, -30, -40, -50]); 9 | }); 10 | -------------------------------------------------------------------------------- /glossary/Event-loop.md: -------------------------------------------------------------------------------- 1 | ### Event loop 2 | 3 | The event loop handles all asynchronous callbacks. 4 | Callbacks are queued in a loop, while other code runs, and will run one by one when the response for each one has been received. 5 | The event loop allows JavaScript to perform non-blocking I/O operations, despite the fact that JavaScript is single-threaded. 6 | -------------------------------------------------------------------------------- /glossary/Functional-programming.md: -------------------------------------------------------------------------------- 1 | ### Functional programming 2 | 3 | Functional programming is a paradigm in which programs are built in a declarative manner using pure functions that avoid shared state and mutable data. 4 | Functions that always return the same value for the same input and don't produce side effects are the pillar of functional programming. 5 | -------------------------------------------------------------------------------- /snippets/isDivisible.md: -------------------------------------------------------------------------------- 1 | ### isDivisible 2 | 3 | Checks if the first numeric argument is divisible by the second one. 4 | 5 | Use the modulo operator (`%`) to check if the remainder is equal to `0`. 6 | 7 | ```js 8 | const isDivisible = (dividend, divisor) => dividend % divisor === 0; 9 | ``` 10 | 11 | ```js 12 | isDivisible(6, 3); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/nodeListToArray.md: -------------------------------------------------------------------------------- 1 | ### nodeListToArray 2 | 3 | Converts a `NodeList` to an array. 4 | 5 | Use spread operator inside new array to convert a `NodeList` to an array. 6 | 7 | ```js 8 | const nodeListToArray = nodeList => [...nodeList]; 9 | ``` 10 | 11 | ```js 12 | nodeListToArray(document.childNodes); // [ , html ] 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/removeNonASCII.md: -------------------------------------------------------------------------------- 1 | ### removeNonASCII 2 | 3 | Removes non-printable ASCII characters. 4 | 5 | Use a regular expression to remove non-printable ASCII characters. 6 | 7 | ```js 8 | const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, ''); 9 | ``` 10 | 11 | ```js 12 | removeNonASCII('äÄçÇéÉêlorem-ipsumöÖÐþúÚ'); // 'lorem-ipsum' 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets_archive/mphToKmph.md: -------------------------------------------------------------------------------- 1 | ### mphToKmph 2 | 3 | Convert miles/hour to kilometers/hour. 4 | 5 | Multiply the constant of proportionality with the argument. 6 | 7 | ```js 8 | const mphToKmph = (mph) => 1.6093440006146922 * mph; 9 | ``` 10 | 11 | ```js 12 | mphToKmph(10); // 16.09344000614692 13 | mphToKmph(85.9); // 138.24264965280207 14 | ``` 15 | -------------------------------------------------------------------------------- /test/curry.test.js: -------------------------------------------------------------------------------- 1 | const {curry} = require('./_30s.js'); 2 | 3 | test('curry is a Function', () => { 4 | expect(curry).toBeInstanceOf(Function); 5 | }); 6 | test('curries a Math.pow', () => { 7 | expect(curry(Math.pow)(2)(10)).toBe(1024); 8 | }); 9 | test('curries a Math.min', () => { 10 | expect(curry(Math.min, 3)(10)(50)(2)).toBe(2); 11 | }); 12 | -------------------------------------------------------------------------------- /test/isPrime.test.js: -------------------------------------------------------------------------------- 1 | const {isPrime} = require('./_30s.js'); 2 | 3 | test('isPrime is a Function', () => { 4 | expect(isPrime).toBeInstanceOf(Function); 5 | }); 6 | test('passed number is a prime', () => { 7 | expect(isPrime(11)).toBeTruthy(); 8 | }); 9 | test('passed number is not a prime', () => { 10 | expect(isPrime(10)).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/omitBy.test.js: -------------------------------------------------------------------------------- 1 | const {omitBy} = require('./_30s.js'); 2 | 3 | test('omitBy is a Function', () => { 4 | expect(omitBy).toBeInstanceOf(Function); 5 | }); 6 | test('Creates an object composed of the properties the given function returns falsy for', () => { 7 | expect(omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number')).toEqual({ b: '2' }); 8 | }); 9 | -------------------------------------------------------------------------------- /snippets/stripHTMLTags.md: -------------------------------------------------------------------------------- 1 | ### stripHTMLTags 2 | 3 | Removes HTML/XML tags from string. 4 | 5 | Use a regular expression to remove HTML/XML tags from a string. 6 | 7 | ```js 8 | const stripHTMLTags = str => str.replace(/<[^>]*>/g, ''); 9 | ``` 10 | 11 | ```js 12 | stripHTMLTags('

lorem ipsum

'); // 'lorem ipsum' 13 | ``` 14 | -------------------------------------------------------------------------------- /test/forEachRight.test.js: -------------------------------------------------------------------------------- 1 | const {forEachRight} = require('./_30s.js'); 2 | 3 | test('forEachRight is a Function', () => { 4 | expect(forEachRight).toBeInstanceOf(Function); 5 | }); 6 | let output = ''; 7 | forEachRight([1, 2, 3, 4], val => (output += val)); 8 | test('Iterates over the array in reverse', () => { 9 | expect(output).toBe('4321'); 10 | }); 11 | -------------------------------------------------------------------------------- /test/pickBy.test.js: -------------------------------------------------------------------------------- 1 | const {pickBy} = require('./_30s.js'); 2 | 3 | test('pickBy is a Function', () => { 4 | expect(pickBy).toBeInstanceOf(Function); 5 | }); 6 | test('Creates an object composed of the properties the given function returns truthy for.', () => { 7 | expect(pickBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number')).toEqual({ a: 1, c: 3 }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/sortCharactersInString.test.js: -------------------------------------------------------------------------------- 1 | const {sortCharactersInString} = require('./_30s.js'); 2 | 3 | test('sortCharactersInString is a Function', () => { 4 | expect(sortCharactersInString).toBeInstanceOf(Function); 5 | }); 6 | test('Alphabetically sorts the characters in a string.', () => { 7 | expect(sortCharactersInString('cabbage')).toBe('aabbceg'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/stripHTMLTags.test.js: -------------------------------------------------------------------------------- 1 | const {stripHTMLTags} = require('./_30s.js'); 2 | 3 | test('stripHTMLTags is a Function', () => { 4 | expect(stripHTMLTags).toBeInstanceOf(Function); 5 | }); 6 | test('Removes HTML tags', () => { 7 | expect(stripHTMLTags('

lorem ipsum


')).toBe( 8 | 'lorem ipsum' 9 | ); 10 | }); 11 | -------------------------------------------------------------------------------- /snippets/isUndefined.md: -------------------------------------------------------------------------------- 1 | ### isUndefined 2 | 3 | Returns `true` if the specified value is `undefined`, `false` otherwise. 4 | 5 | Use the strict equality operator to check if the value and of `val` are equal to `undefined`. 6 | 7 | ```js 8 | const isUndefined = val => val === undefined; 9 | ``` 10 | 11 | ```js 12 | isUndefined(undefined); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /test/JSONToDate.test.js: -------------------------------------------------------------------------------- 1 | const {JSONToDate} = require('./_30s.js'); 2 | 3 | test('JSONToDate is a Function', () => { 4 | expect(JSONToDate).toBeInstanceOf(Function); 5 | }); 6 | test('JSONToDate returns the correct date string', () => { 7 | var reg = new RegExp(`Date(${Date.parse('March 14,2017')})`); 8 | expect(JSONToDate(reg)).toBe('14/3/2017'); 9 | }); 10 | -------------------------------------------------------------------------------- /test/dropRightWhile.test.js: -------------------------------------------------------------------------------- 1 | const {dropRightWhile} = require('./_30s.js'); 2 | 3 | test('dropRightWhile is a Function', () => { 4 | expect(dropRightWhile).toBeInstanceOf(Function); 5 | }); 6 | test('Removes elements from the end of an array until the passed function returns true.', () => { 7 | expect(dropRightWhile([1, 2, 3, 4], n => n < 3)).toEqual([1, 2]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/hasClass.test.js: -------------------------------------------------------------------------------- 1 | const {hasClass} = require('./_30s.js'); 2 | 3 | test('hasClass is a Function', () => { 4 | expect(hasClass).toBeInstanceOf(Function); 5 | }); 6 | test('hasClass returns the proper value', () => { 7 | let el = document.createElement('div'); 8 | el.classList.add('myClass'); 9 | expect(hasClass(el, 'myClass')).toBeTruthy(); 10 | }); 11 | -------------------------------------------------------------------------------- /test/hide.test.js: -------------------------------------------------------------------------------- 1 | const {hide} = require('./_30s.js'); 2 | 3 | test('hide is a Function', () => { 4 | expect(hide).toBeInstanceOf(Function); 5 | }); 6 | test('hide hides an element', () => { 7 | let el = document.createElement('div'); 8 | el.setAttribute('style', 'display: block;'); 9 | hide(el); 10 | expect(el.style.display).toBe('none'); 11 | }); 12 | -------------------------------------------------------------------------------- /test/show.test.js: -------------------------------------------------------------------------------- 1 | const {show} = require('./_30s.js'); 2 | 3 | test('show is a Function', () => { 4 | expect(show).toBeInstanceOf(Function); 5 | }); 6 | test('show shows an element', () => { 7 | let el = document.createElement('div'); 8 | el.setAttribute('style', 'display: none;'); 9 | show(el); 10 | expect(el.style.display).not.toBe('none'); 11 | }); 12 | -------------------------------------------------------------------------------- /test/stableSort.test.js: -------------------------------------------------------------------------------- 1 | const {stableSort} = require('./_30s.js'); 2 | 3 | test('stableSort is a Function', () => { 4 | expect(stableSort).toBeInstanceOf(Function); 5 | }); 6 | const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 7 | const compare = () => 0; 8 | test('Array is properly sorted', () => { 9 | expect(stableSort(arr, compare)).toEqual(arr); 10 | }); 11 | -------------------------------------------------------------------------------- /snippets/isAfterDate.md: -------------------------------------------------------------------------------- 1 | ### isAfterDate 2 | 3 | Check if a date is after another date. 4 | 5 | Use the greater than operator (`>`) to check if the first date comes after the second one. 6 | 7 | ```js 8 | const isAfterDate = (dateA, dateB) => dateA > dateB; 9 | ``` 10 | 11 | ```js 12 | isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /test/escapeHTML.test.js: -------------------------------------------------------------------------------- 1 | const {escapeHTML} = require('./_30s.js'); 2 | 3 | test('escapeHTML is a Function', () => { 4 | expect(escapeHTML).toBeInstanceOf(Function); 5 | }); 6 | test('Escapes a string for use in HTML', () => { 7 | expect(escapeHTML('Me & you')).toBe( 8 | '<a href="#">Me & you</a>' 9 | ); 10 | }); 11 | -------------------------------------------------------------------------------- /test/get.test.js: -------------------------------------------------------------------------------- 1 | const {get} = require('./_30s.js'); 2 | 3 | test('get is a Function', () => { 4 | expect(get).toBeInstanceOf(Function); 5 | }); 6 | const obj = { selector: { to: { val: 'val to get' } } }; 7 | test('Retrieve a property indicated by the selector from an object.', () => { 8 | expect(get(obj, 'selector.to.val')).toEqual(['val to get']); 9 | }); 10 | -------------------------------------------------------------------------------- /test/throttle.test.js: -------------------------------------------------------------------------------- 1 | const {throttle} = require('./_30s.js'); 2 | 3 | test('throttle is a Function', () => { 4 | expect(throttle).toBeInstanceOf(Function); 5 | }); 6 | test('throttle returns a function', () => { 7 | let throttled = throttle(x => x, 100000); 8 | expect(throttled).toBeInstanceOf(Function); 9 | expect(throttled(10)).toBe(undefined); 10 | }); 11 | -------------------------------------------------------------------------------- /snippets/isBeforeDate.md: -------------------------------------------------------------------------------- 1 | ### isBeforeDate 2 | 3 | Check if a date is before another date. 4 | 5 | Use the less than operator (`<`) to check if the first date comes before the second one. 6 | 7 | ```js 8 | const isBeforeDate = (dateA, dateB) => dateA < dateB; 9 | ``` 10 | 11 | ```js 12 | isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/isEven.md: -------------------------------------------------------------------------------- 1 | ### isEven 2 | 3 | Returns `true` if the given number is even, `false` otherwise. 4 | 5 | Checks whether a number is odd or even using the modulo (`%`) operator. 6 | Returns `true` if the number is even, `false` if the number is odd. 7 | 8 | ```js 9 | const isEven = num => num % 2 === 0; 10 | ``` 11 | 12 | ```js 13 | isEven(3); // false 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/shallowClone.md: -------------------------------------------------------------------------------- 1 | ### shallowClone 2 | 3 | Creates a shallow clone of an object. 4 | 5 | Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of the original. 6 | 7 | ```js 8 | const shallowClone = obj => Object.assign({}, obj); 9 | ``` 10 | 11 | ```js 12 | const a = { x: true, y: 1 }; 13 | const b = shallowClone(a); // a !== b 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/sum.md: -------------------------------------------------------------------------------- 1 | ### sum 2 | 3 | Returns the sum of two or more numbers/arrays. 4 | 5 | Use `Array.prototype.reduce()` to add each value to an accumulator, initialized with a value of `0`. 6 | 7 | ```js 8 | const sum = (...arr) => [...arr].reduce((acc, val) => acc + val, 0); 9 | ``` 10 | 11 | ```js 12 | sum(1, 2, 3, 4); // 10 13 | sum(...[1, 2, 3, 4]); // 10 14 | ``` 15 | -------------------------------------------------------------------------------- /test/pullBy.test.js: -------------------------------------------------------------------------------- 1 | const {pullBy} = require('./_30s.js'); 2 | 3 | test('pullBy is a Function', () => { 4 | expect(pullBy).toBeInstanceOf(Function); 5 | }); 6 | var myArray = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }]; 7 | pullBy(myArray, [{ x: 1 }, { x: 3 }], o => o.x); 8 | test('Pulls the specified values', () => { 9 | expect(myArray).toEqual([{ x: 2 }]); 10 | }); 11 | -------------------------------------------------------------------------------- /docs/clipboard.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /glossary/CSV.md: -------------------------------------------------------------------------------- 1 | ### CSV 2 | 3 | CSV stands for Comma-Separated Values and is a storage format for tabular data. 4 | CSV documents are plaintext documents where each line represents a table row, with table columns separated by commas or some other delimiter (e.g. semicolons). 5 | The first line of a CSV document sometimes consists of the table column headings for the data to follow. 6 | -------------------------------------------------------------------------------- /glossary/IP.md: -------------------------------------------------------------------------------- 1 | ### IP 2 | 3 | An IP address is a number assigned to a device connected to a network that uses the Internet protocol. 4 | Two IP versions are currently in use - IPv4, the older version of the communication protocol (e.g. 192.168.1.100) and IPv6, the newest version of the communication protocol which allows for many different IP addresses (e.g. 0:0:0:0:ffff:c0a8:164). 5 | -------------------------------------------------------------------------------- /snippets/hide.md: -------------------------------------------------------------------------------- 1 | ### hide 2 | 3 | Hides all the elements specified. 4 | 5 | Use `NodeList.prototype.forEach()` to apply `display: none` to each element specified. 6 | 7 | ```js 8 | const hide = (...el) => [...el].forEach(e => (e.style.display = 'none')); 9 | ``` 10 | 11 | ```js 12 | hide(document.querySelectorAll('img')); // Hides all elements on the page 13 | ``` 14 | -------------------------------------------------------------------------------- /test/isBoolean.test.js: -------------------------------------------------------------------------------- 1 | const {isBoolean} = require('./_30s.js'); 2 | 3 | test('isBoolean is a Function', () => { 4 | expect(isBoolean).toBeInstanceOf(Function); 5 | }); 6 | test('passed value is not a boolean', () => { 7 | expect(isBoolean(null)).toBeFalsy(); 8 | }); 9 | test('passed value is not a boolean', () => { 10 | expect(isBoolean(false)).toBeTruthy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/percentile.test.js: -------------------------------------------------------------------------------- 1 | const {percentile} = require('./_30s.js'); 2 | 3 | test('percentile is a Function', () => { 4 | expect(percentile).toBeInstanceOf(Function); 5 | }); 6 | test('Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.', () => { 7 | expect(percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6)).toBe(55); 8 | }); 9 | -------------------------------------------------------------------------------- /test/unescapeHTML.test.js: -------------------------------------------------------------------------------- 1 | const {unescapeHTML} = require('./_30s.js'); 2 | 3 | test('unescapeHTML is a Function', () => { 4 | expect(unescapeHTML).toBeInstanceOf(Function); 5 | }); 6 | test('Unescapes escaped HTML characters.', () => { 7 | expect(unescapeHTML('<a href="#">Me & you</a>')).toBe( 8 | 'Me & you' 9 | ); 10 | }); 11 | -------------------------------------------------------------------------------- /glossary/Strict-mode.md: -------------------------------------------------------------------------------- 1 | ### Strict mode 2 | 3 | JavaScript's strict mode is a JavaScript feature that allows developers to use a more restrictive variant of JavaScript and it can be enabled by adding `'use strict';` at the very top of their code. 4 | Strict mode elimiated some silent errors, might improve performance and changes the behavior of `eval` and `arguments` among other things. 5 | -------------------------------------------------------------------------------- /snippets_archive/countVowels.md: -------------------------------------------------------------------------------- 1 | ### countVowels 2 | 3 | Retuns `number` of vowels in provided string. 4 | 5 | Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a `string`. 6 | 7 | ```js 8 | const countVowels = str => (str.match(/[aeiou]/gi) || []).length; 9 | ``` 10 | 11 | ```js 12 | countVowels('foobar'); // 3 13 | countVowels('gym'); // 0 14 | ``` 15 | -------------------------------------------------------------------------------- /test/degreesToRads.test.js: -------------------------------------------------------------------------------- 1 | const {degreesToRads} = require('./_30s.js'); 2 | 3 | // const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff; 4 | test('degreesToRads is a Function', () => { 5 | expect(degreesToRads).toBeInstanceOf(Function); 6 | }); 7 | test('Returns the appropriate value', () => { 8 | expect(degreesToRads(90.0)).toBeCloseTo(Math.PI / 2, 3); 9 | }); 10 | -------------------------------------------------------------------------------- /test/delay.test.js: -------------------------------------------------------------------------------- 1 | const {delay} = require('./_30s.js'); 2 | 3 | test('delay is a Function', () => { 4 | expect(delay).toBeInstanceOf(Function); 5 | }); 6 | test('Works as expecting, passing arguments properly', done => { 7 | delay( 8 | function(text) { 9 | expect(text).toBe('test'); 10 | done(); 11 | }, 12 | 1000, 13 | 'test' 14 | ); 15 | }); 16 | -------------------------------------------------------------------------------- /test/getStyle.test.js: -------------------------------------------------------------------------------- 1 | const {getStyle} = require('./_30s.js'); 2 | 3 | test('getStyle is a Function', () => { 4 | expect(getStyle).toBeInstanceOf(Function); 5 | }); 6 | test('getStyle returns the proper value', () => { 7 | let el = document.createElement('div'); 8 | el.setAttribute('style', 'font-size: 20px;'); 9 | expect(getStyle(el, 'font-size')).toBe('20px'); 10 | }); 11 | -------------------------------------------------------------------------------- /test/httpGet.test.js: -------------------------------------------------------------------------------- 1 | const {httpGet} = require('./_30s.js'); 2 | 3 | test('httpGet is a Function', () => { 4 | expect(httpGet).toBeInstanceOf(Function); 5 | }); 6 | test('httpGet does not throw errors', () => { 7 | expect(() => { 8 | httpGet('http://localhost', x => x, console.log); 9 | httpGet('http://localhost', x => x); 10 | }).not.toThrow(TypeError); 11 | }); 12 | -------------------------------------------------------------------------------- /test/httpPut.test.js: -------------------------------------------------------------------------------- 1 | const {httpPut} = require('./_30s.js'); 2 | 3 | test('httpPut is a Function', () => { 4 | expect(httpPut).toBeInstanceOf(Function); 5 | }); 6 | test('httpPut does not throw errors', () => { 7 | expect(() => { 8 | httpPut('http://localhost', x => x, console.log); 9 | httpPut('http://localhost', x => x); 10 | }).not.toThrow(TypeError); 11 | }); 12 | -------------------------------------------------------------------------------- /test/isFunction.test.js: -------------------------------------------------------------------------------- 1 | const {isFunction} = require('./_30s.js'); 2 | 3 | test('isFunction is a Function', () => { 4 | expect(isFunction).toBeInstanceOf(Function); 5 | }); 6 | test('passed value is a function', () => { 7 | expect(isFunction(x => x)).toBeTruthy(); 8 | }); 9 | test('passed value is not a function', () => { 10 | expect(isFunction('x')).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/isSimilar.test.js: -------------------------------------------------------------------------------- 1 | const {isSimilar} = require('./_30s.js'); 2 | 3 | test('isSimilar is a Function', () => { 4 | expect(isSimilar).toBeInstanceOf(Function); 5 | }); 6 | test('isSimilar returns true', () => { 7 | expect(isSimilar('rt', 'Rohit')).toBeTruthy(); 8 | }); 9 | test('isSimilar returns false', () => { 10 | expect(isSimilar('tr', 'Rohit')).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/removeVowels.test.js: -------------------------------------------------------------------------------- 1 | const {removeVowels} = require('./_30s.js'); 2 | 3 | test('removeVowels is a Function', () => { 4 | expect(removeVowels).toBeInstanceOf(Function); 5 | }); 6 | test('Removes vowels.', () => { 7 | expect(removeVowels('foobAr')).toBe('fbr'); 8 | }); 9 | test('Replaces vowels.', () => { 10 | expect(removeVowels('foobAr', '*')).toBe('f**b*r'); 11 | }); 12 | -------------------------------------------------------------------------------- /glossary/HTTP-and-HTTPS.md: -------------------------------------------------------------------------------- 1 | ### HTTP and HTTPS 2 | 3 | The HyperText Transfer Protocol (HTTP) is the underlying network protocol that enables transfer of hypermedia documents on the Web, usually between a client and a server. 4 | The HyperText Transfer Protocol Secure (HTTPS) is an encrypted version of the HTTP protocol, that uses SSL to encrypt all data transferred between a client and a server. 5 | -------------------------------------------------------------------------------- /snippets/everyNth.md: -------------------------------------------------------------------------------- 1 | ### everyNth 2 | 3 | Returns every nth element in an array. 4 | 5 | Use `Array.prototype.filter()` to create a new array that contains every nth element of a given array. 6 | 7 | 8 | 9 | ```js 10 | const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1); 11 | ``` 12 | 13 | ```js 14 | everyNth([1, 2, 3, 4, 5, 6], 2); // [ 2, 4, 6 ] 15 | ``` 16 | -------------------------------------------------------------------------------- /snippets/getStyle.md: -------------------------------------------------------------------------------- 1 | ### getStyle 2 | 3 | Returns the value of a CSS rule for the specified element. 4 | 5 | Use `Window.getComputedStyle()` to get the value of the CSS rule for the specified element. 6 | 7 | ```js 8 | const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName]; 9 | ``` 10 | 11 | ```js 12 | getStyle(document.querySelector('p'), 'font-size'); // '16px' 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/objectFromPairs.md: -------------------------------------------------------------------------------- 1 | ### objectFromPairs 2 | 3 | Creates an object from the given key-value pairs. 4 | 5 | Use `Array.prototype.reduce()` to create and combine key-value pairs. 6 | 7 | ```js 8 | const objectFromPairs = arr => arr.reduce((a, [key, val]) => ((a[key] = val), a), {}); 9 | ``` 10 | 11 | ```js 12 | objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2} 13 | ``` 14 | -------------------------------------------------------------------------------- /test/createElement.test.js: -------------------------------------------------------------------------------- 1 | const {createElement} = require('./_30s.js'); 2 | 3 | test('createElement is a Function', () => { 4 | expect(createElement).toBeInstanceOf(Function); 5 | }); 6 | test('createElement creates an element', () => { 7 | expect(createElement( 8 | `
9 |

Hello!

10 |
` 11 | ).className).toEqual('container'); 12 | }); 13 | -------------------------------------------------------------------------------- /test/flip.test.js: -------------------------------------------------------------------------------- 1 | const {flip} = require('./_30s.js'); 2 | 3 | test('flip is a Function', () => { 4 | expect(flip).toBeInstanceOf(Function); 5 | }); 6 | let a = { name: 'John Smith' }; 7 | let b = {}; 8 | const mergeFrom = flip(Object.assign); 9 | let mergePerson = mergeFrom.bind(null, a); 10 | test('Flips argument order', () => { 11 | expect(mergePerson(b)).toEqual(a); 12 | }); 13 | -------------------------------------------------------------------------------- /test/forOwnRight.test.js: -------------------------------------------------------------------------------- 1 | const {forOwnRight} = require('./_30s.js'); 2 | 3 | test('forOwnRight is a Function', () => { 4 | expect(forOwnRight).toBeInstanceOf(Function); 5 | }); 6 | let output = []; 7 | forOwnRight({ foo: 'bar', a: 1 }, v => output.push(v)); 8 | test("Iterates over an element's key-value pairs in reverse", () => { 9 | expect(output).toEqual([1, 'bar']); 10 | }); 11 | -------------------------------------------------------------------------------- /test/getDaysDiffBetweenDates.test.js: -------------------------------------------------------------------------------- 1 | const {getDaysDiffBetweenDates} = require('./_30s.js'); 2 | 3 | test('getDaysDiffBetweenDates is a Function', () => { 4 | expect(getDaysDiffBetweenDates).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the difference in days between two dates', () => { 7 | expect(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22'))).toBe(9); 8 | }); 9 | -------------------------------------------------------------------------------- /test/httpPost.test.js: -------------------------------------------------------------------------------- 1 | const {httpPost} = require('./_30s.js'); 2 | 3 | test('httpPost is a Function', () => { 4 | expect(httpPost).toBeInstanceOf(Function); 5 | }); 6 | test('httpPost does not throw errors', () => { 7 | expect(() => { 8 | httpPost('http://localhost', x => x, console.log); 9 | httpPost('http://localhost', x => x); 10 | }).not.toThrow(TypeError); 11 | }); 12 | -------------------------------------------------------------------------------- /glossary/Event-driven-programming.md: -------------------------------------------------------------------------------- 1 | ### Event-driven programming 2 | 3 | Event-driven programming is a programming paradigm in which the flow of the program is determined by events (e.g. user actions, thread messages, sensor outputs). 4 | In event-driven applications, there is usually a main loop that listens for events and trigger callback functions accordingly when one of these events is detected. 5 | -------------------------------------------------------------------------------- /test/bifurcate.test.js: -------------------------------------------------------------------------------- 1 | const {bifurcate} = require('./_30s.js'); 2 | 3 | test('bifurcate is a Function', () => { 4 | expect(bifurcate).toBeInstanceOf(Function); 5 | }); 6 | test('Splits the collection into two groups', () => { 7 | expect(bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true])).toEqual([ 8 | ['beep', 'boop', 'bar'], 9 | ['foo'] 10 | ]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/bifurcateBy.test.js: -------------------------------------------------------------------------------- 1 | const {bifurcateBy} = require('./_30s.js'); 2 | 3 | test('bifurcateBy is a Function', () => { 4 | expect(bifurcateBy).toBeInstanceOf(Function); 5 | }); 6 | test('Splits the collection into two groups', () => { 7 | expect(bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b')).toEqual([ 8 | ['beep', 'boop', 'bar'], 9 | ['foo'] 10 | ]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/getColonTimeFromDate.test.js: -------------------------------------------------------------------------------- 1 | const {getColonTimeFromDate} = require('./_30s.js'); 2 | 3 | test('getColonTimeFromDate is a Function', () => { 4 | expect(getColonTimeFromDate).toBeInstanceOf(Function); 5 | }); 6 | test('Gets the time in the proper format.', () => { 7 | let date = new Date(); 8 | expect(getColonTimeFromDate(date)).toEqual(date.toTimeString().slice(0, 8)); 9 | }); 10 | -------------------------------------------------------------------------------- /test/palindrome.test.js: -------------------------------------------------------------------------------- 1 | const {palindrome} = require('./_30s.js'); 2 | 3 | test('palindrome is a Function', () => { 4 | expect(palindrome).toBeInstanceOf(Function); 5 | }); 6 | test('Given string is a palindrome', () => { 7 | expect(palindrome('taco cat')).toBeTruthy(); 8 | }); 9 | test('Given string is not a palindrome', () => { 10 | expect(palindrome('foobar')).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/size.test.js: -------------------------------------------------------------------------------- 1 | const {size} = require('./_30s.js'); 2 | 3 | test('size is a Function', () => { 4 | expect(size).toBeInstanceOf(Function); 5 | }); 6 | test('Get size of arrays, objects or strings.', () => { 7 | expect(size([1, 2, 3, 4, 5])).toBe(5); 8 | }); 9 | test('Get size of arrays, objects or strings.', () => { 10 | expect(size({ one: 1, two: 2, three: 3 })).toBe(3); 11 | }); 12 | -------------------------------------------------------------------------------- /test/unionWith.test.js: -------------------------------------------------------------------------------- 1 | const {unionWith} = require('./_30s.js'); 2 | 3 | test('unionWith is a Function', () => { 4 | expect(unionWith).toBeInstanceOf(Function); 5 | }); 6 | test('Produces the appropriate results', () => { 7 | expect( 8 | unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)) 9 | ).toEqual([1, 1.2, 1.5, 3, 0, 3.9]); 10 | }); 11 | -------------------------------------------------------------------------------- /snippets/isNil.md: -------------------------------------------------------------------------------- 1 | ### isNil 2 | 3 | Returns `true` if the specified value is `null` or `undefined`, `false` otherwise. 4 | 5 | Use the strict equality operator to check if the value and of `val` are equal to `null` or `undefined`. 6 | 7 | ```js 8 | const isNil = val => val === undefined || val === null; 9 | ``` 10 | 11 | ```js 12 | isNil(null); // true 13 | isNil(undefined); // true 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/mapNumRange.md: -------------------------------------------------------------------------------- 1 | ### mapNumRange 2 | 3 | Maps a number from one range to another range. 4 | 5 | Returns `num` mapped between `outMin`-`outMax` from `inMin`-`inMax`. 6 | 7 | ```js 8 | const mapNumRange = (num, inMin, inMax, outMin, outMax) => 9 | ((num - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin; 10 | ``` 11 | 12 | ```js 13 | mapNumRange(5, 0, 10, 0, 100); // 50 14 | ``` 15 | -------------------------------------------------------------------------------- /test/differenceWith.test.js: -------------------------------------------------------------------------------- 1 | const {differenceWith} = require('./_30s.js'); 2 | 3 | test('differenceWith is a Function', () => { 4 | expect(differenceWith).toBeInstanceOf(Function); 5 | }); 6 | test('Filters out all values from an array', () => { 7 | expect( 8 | differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)) 9 | ).toEqual([1, 1.2]); 10 | }); 11 | -------------------------------------------------------------------------------- /test/rearg.test.js: -------------------------------------------------------------------------------- 1 | const {rearg} = require('./_30s.js'); 2 | 3 | test('rearg is a Function', () => { 4 | expect(rearg).toBeInstanceOf(Function); 5 | }); 6 | var rearged = rearg( 7 | function(a, b, c) { 8 | return [a, b, c]; 9 | }, 10 | [2, 0, 1] 11 | ); 12 | test('Reorders arguments in invoked function', () => { 13 | expect(rearged('b', 'c', 'a')).toEqual(['a', 'b', 'c']); 14 | }); 15 | -------------------------------------------------------------------------------- /snippets/functionName.md: -------------------------------------------------------------------------------- 1 | ### functionName 2 | 3 | Logs the name of a function. 4 | 5 | Use `console.debug()` and the `name` property of the passed method to log the method's name to the `debug` channel of the console. 6 | 7 | ```js 8 | const functionName = fn => (console.debug(fn.name), fn); 9 | ``` 10 | 11 | ```js 12 | functionName(Math.max); // max (logged in debug channel of console) 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/getType.md: -------------------------------------------------------------------------------- 1 | ### getType 2 | 3 | Returns the native type of a value. 4 | 5 | Returns lowercased constructor name of value, `"undefined"` or `"null"` if value is `undefined` or `null`. 6 | 7 | ```js 8 | const getType = v => 9 | v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase(); 10 | ``` 11 | 12 | ```js 13 | getType(new Set([1, 2, 3])); // 'set' 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/hasClass.md: -------------------------------------------------------------------------------- 1 | ### hasClass 2 | 3 | Returns `true` if the element has the specified class, `false` otherwise. 4 | 5 | Use `element.classList.contains()` to check if the element has the specified class. 6 | 7 | ```js 8 | const hasClass = (el, className) => el.classList.contains(className); 9 | ``` 10 | 11 | ```js 12 | hasClass(document.querySelector('p.special'), 'special'); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/isLowerCase.md: -------------------------------------------------------------------------------- 1 | ### isLowerCase 2 | 3 | Checks if a string is lower case. 4 | 5 | Convert the given string to lower case, using `String.toLowerCase()` and compare it to the original. 6 | 7 | ```js 8 | const isLowerCase = str => str === str.toLowerCase(); 9 | ``` 10 | 11 | ```js 12 | isLowerCase('abc'); // true 13 | isLowerCase('a3@$'); // true 14 | isLowerCase('Ab4'); // false 15 | ``` 16 | -------------------------------------------------------------------------------- /snippets/randomNumberInRange.md: -------------------------------------------------------------------------------- 1 | ### randomNumberInRange 2 | 3 | Returns a random number in the specified range. 4 | 5 | Use `Math.random()` to generate a random value, map it to the desired range using multiplication. 6 | 7 | ```js 8 | const randomNumberInRange = (min, max) => Math.random() * (max - min) + min; 9 | ``` 10 | 11 | ```js 12 | randomNumberInRange(2, 10); // 6.0211363285087005 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/splitLines.md: -------------------------------------------------------------------------------- 1 | ### splitLines 2 | 3 | Splits a multiline string into an array of lines. 4 | 5 | Use `String.prototype.split()` and a regular expression to match line breaks and create an array. 6 | 7 | ```js 8 | const splitLines = str => str.split(/\r?\n/); 9 | ``` 10 | 11 | ```js 12 | splitLines('This\nis a\nmultiline\nstring.\n'); // ['This', 'is a', 'multiline', 'string.' , ''] 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/toDecimalMark.md: -------------------------------------------------------------------------------- 1 | ### toDecimalMark 2 | 3 | Use `toLocaleString()` to convert a float-point arithmetic to the [Decimal mark](https://en.wikipedia.org/wiki/Decimal_mark) form. It makes a comma separated string from a number. 4 | 5 | ```js 6 | const toDecimalMark = num => num.toLocaleString('en-US'); 7 | ``` 8 | 9 | ```js 10 | toDecimalMark(12305030388.9087); // "12,305,030,388.909" 11 | ``` 12 | -------------------------------------------------------------------------------- /test/countVowels.test.js: -------------------------------------------------------------------------------- 1 | const {countVowels} = require('./_30s.js'); 2 | 3 | test('countVowels is a Function', () => { 4 | expect(countVowels).toBeInstanceOf(Function); 5 | }); 6 | test('countVowels returns the correct count', () => { 7 | expect(countVowels('foobar')).toBe(3); 8 | }); 9 | test('countVowels returns the correct count', () => { 10 | expect(countVowels('ggg')).toBe(0); 11 | }); 12 | -------------------------------------------------------------------------------- /test/httpDelete.test.js: -------------------------------------------------------------------------------- 1 | const {httpDelete} = require('./_30s.js'); 2 | 3 | test('httpDelete is a Function', () => { 4 | expect(httpDelete).toBeInstanceOf(Function); 5 | }); 6 | test('httpDelete does not throw errors', () => { 7 | expect(() => { 8 | httpDelete('http://localhost', x => x, console.log); 9 | httpDelete('http://localhost', x => x); 10 | }).not.toThrow(TypeError); 11 | }); 12 | -------------------------------------------------------------------------------- /test/lcm.test.js: -------------------------------------------------------------------------------- 1 | const {lcm} = require('./_30s.js'); 2 | 3 | test('lcm is a Function', () => { 4 | expect(lcm).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the least common multiple of two or more numbers.', () => { 7 | expect(lcm(12, 7)).toBe(84); 8 | }); 9 | test('Returns the least common multiple of two or more numbers.', () => { 10 | expect(lcm(...[1, 3, 4, 5])).toBe(60); 11 | }); 12 | -------------------------------------------------------------------------------- /test/mapValues.test.js: -------------------------------------------------------------------------------- 1 | const {mapValues} = require('./_30s.js'); 2 | 3 | test('mapValues is a Function', () => { 4 | expect(mapValues).toBeInstanceOf(Function); 5 | }); 6 | const users = { 7 | fred: { user: 'fred', age: 40 }, 8 | pebbles: { user: 'pebbles', age: 1 } 9 | }; 10 | test('Maps values', () => { 11 | expect(mapValues(users, u => u.age)).toEqual({ fred: 40, pebbles: 1 }); 12 | }); 13 | -------------------------------------------------------------------------------- /test/partial.test.js: -------------------------------------------------------------------------------- 1 | const {partial} = require('./_30s.js'); 2 | 3 | test('partial is a Function', () => { 4 | expect(partial).toBeInstanceOf(Function); 5 | }); 6 | function greet(greeting, name) { 7 | return greeting + ' ' + name + '!'; 8 | } 9 | const greetHello = partial(greet, 'Hello'); 10 | test('Prepends arguments', () => { 11 | expect(greetHello('John')).toBe('Hello John!'); 12 | }); 13 | -------------------------------------------------------------------------------- /test/solveRPN.test.js: -------------------------------------------------------------------------------- 1 | const {solveRPN} = require('./_30s.js'); 2 | 3 | test('solveRPN is a Function', () => { 4 | expect(solveRPN).toBeInstanceOf(Function); 5 | }); 6 | test('solveRPN returns the correct result', () => { 7 | expect(solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -')).toBe(5); 8 | }); 9 | test('solveRPN returns the correct result', () => { 10 | expect(solveRPN('2 3 ^')).toBe(8); 11 | }); 12 | -------------------------------------------------------------------------------- /snippets/digitize.md: -------------------------------------------------------------------------------- 1 | ### digitize 2 | 3 | Converts a number to an array of digits. 4 | 5 | Convert the number to a string, using the spread operator (`...`) to build an array. 6 | Use `Array.prototype.map()` and `parseInt()` to transform each value to an integer. 7 | 8 | ```js 9 | const digitize = n => [...`${n}`].map(i => parseInt(i)); 10 | ``` 11 | 12 | ```js 13 | digitize(123); // [1, 2, 3] 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/isNegativeZero.md: -------------------------------------------------------------------------------- 1 | ### isNegativeZero 2 | 3 | Checks if the given value is equal to negative zero (`-0`). 4 | 5 | Checks whether a passed value is equal to `0` and if `1` divided by the value equals `-Infinity`. 6 | 7 | ```js 8 | const isNegativeZero = val => val === 0 && 1 / val === -Infinity; 9 | ``` 10 | 11 | ```js 12 | isNegativeZero(-0); // true 13 | isNegativeZero(0); // false 14 | ``` 15 | -------------------------------------------------------------------------------- /test/attempt.test.js: -------------------------------------------------------------------------------- 1 | const {attempt} = require('./_30s.js'); 2 | 3 | test('attempt is a Function', () => { 4 | expect(attempt).toBeInstanceOf(Function); 5 | }); 6 | test('Returns a value', () => { 7 | expect(attempt(() => 0)).toBe(0); 8 | }); 9 | test('Returns an error', () => { 10 | expect( 11 | attempt(() => { 12 | throw new Error(); 13 | }) 14 | ).toBeInstanceOf(Error); 15 | }); 16 | -------------------------------------------------------------------------------- /glossary/Function.md: -------------------------------------------------------------------------------- 1 | ### Function 2 | 3 | Functions are self-contained blocks of code with their own scope, that can be called by other code and are usually associated with a unique identifier. 4 | Functions accept input in the form of arguments and can optionally return an output (if no `return` statement is present, the default value of `undefined` will be returned instead). 5 | JavaScript functions are also objects. 6 | -------------------------------------------------------------------------------- /snippets/show.md: -------------------------------------------------------------------------------- 1 | ### show 2 | 3 | Shows all the elements specified. 4 | 5 | Use the spread operator (`...`) and `Array.prototype.forEach()` to clear the `display` property for each element specified. 6 | 7 | ```js 8 | const show = (...el) => [...el].forEach(e => (e.style.display = '')); 9 | ``` 10 | 11 | ```js 12 | show(...document.querySelectorAll('img')); // Shows all elements on the page 13 | ``` 14 | -------------------------------------------------------------------------------- /test/bindAll.test.js: -------------------------------------------------------------------------------- 1 | const {bindAll} = require('./_30s.js'); 2 | 3 | test('bindAll is a Function', () => { 4 | expect(bindAll).toBeInstanceOf(Function); 5 | }); 6 | var view = { 7 | label: 'docs', 8 | click() { 9 | return 'clicked ' + this.label; 10 | } 11 | }; 12 | bindAll(view, 'click'); 13 | test('Binds to an object context', () => { 14 | expect(view.click()).toBe('clicked docs'); 15 | }); 16 | -------------------------------------------------------------------------------- /test/flatten.test.js: -------------------------------------------------------------------------------- 1 | const {flatten} = require('./_30s.js'); 2 | 3 | test('flatten is a Function', () => { 4 | expect(flatten).toBeInstanceOf(Function); 5 | }); 6 | test('Flattens an array', () => { 7 | expect(flatten([1, [2], 3, 4])).toEqual([1, 2, 3, 4]); 8 | }); 9 | test('Flattens an array', () => { 10 | expect(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2)).toEqual([1, 2, 3, [4, 5], 6, 7, 8]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/intersectionBy.test.js: -------------------------------------------------------------------------------- 1 | const {intersectionBy} = require('./_30s.js'); 2 | 3 | test('intersectionBy is a Function', () => { 4 | expect(intersectionBy).toBeInstanceOf(Function); 5 | }); 6 | test('Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both', () => { 7 | expect(intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual([2.1]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/maxN.test.js: -------------------------------------------------------------------------------- 1 | const {maxN} = require('./_30s.js'); 2 | 3 | test('maxN is a Function', () => { 4 | expect(maxN).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the n maximum elements from the provided array', () => { 7 | expect(maxN([1, 2, 3])).toEqual([3]); 8 | }); 9 | test('Returns the n maximum elements from the provided array', () => { 10 | expect(maxN([1, 2, 3], 2)).toEqual([3, 2]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/minN.test.js: -------------------------------------------------------------------------------- 1 | const {minN} = require('./_30s.js'); 2 | 3 | test('minN is a Function', () => { 4 | expect(minN).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the n minimum elements from the provided array', () => { 7 | expect(minN([1, 2, 3])).toEqual([1]); 8 | }); 9 | test('Returns the n minimum elements from the provided array', () => { 10 | expect(minN([1, 2, 3], 2)).toEqual([1, 2]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/spreadOver.test.js: -------------------------------------------------------------------------------- 1 | const {spreadOver} = require('./_30s.js'); 2 | 3 | test('spreadOver is a Function', () => { 4 | expect(spreadOver).toBeInstanceOf(Function); 5 | }); 6 | const arrayMax = spreadOver(Math.max); 7 | test('Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.', () => { 8 | expect(arrayMax([1, 2, 3])).toBe(3); 9 | }); 10 | -------------------------------------------------------------------------------- /test/toggleClass.test.js: -------------------------------------------------------------------------------- 1 | const {toggleClass} = require('./_30s.js'); 2 | 3 | test('toggleClass is a Function', () => { 4 | expect(toggleClass).toBeInstanceOf(Function); 5 | }); 6 | test('toggleClass toggles the class', () => { 7 | let el = document.createElement('div'); 8 | el.classList.add('myClass'); 9 | toggleClass(el, 'myClass'); 10 | expect(el.classList.contains('myClass')).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /snippets/isUpperCase.md: -------------------------------------------------------------------------------- 1 | ### isUpperCase 2 | 3 | Checks if a string is upper case. 4 | 5 | Convert the given string to upper case, using `String.prototype.toUpperCase()` and compare it to the original. 6 | 7 | 8 | ```js 9 | const isUpperCase = str => str === str.toUpperCase(); 10 | ``` 11 | 12 | ```js 13 | isUpperCase('ABC'); // true 14 | isLowerCase('A3@$'); // true 15 | isLowerCase('aB4'); // false 16 | ``` 17 | -------------------------------------------------------------------------------- /snippets/serializeCookie.md: -------------------------------------------------------------------------------- 1 | ### serializeCookie 2 | 3 | Serialize a cookie name-value pair into a Set-Cookie header string. 4 | 5 | Use template literals and `encodeURIComponent()` to create the appropriate string. 6 | 7 | ```js 8 | const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`; 9 | ``` 10 | 11 | ```js 12 | serializeCookie('foo', 'bar'); // 'foo=bar' 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/toggleClass.md: -------------------------------------------------------------------------------- 1 | ### toggleClass 2 | 3 | Toggle a class for an element. 4 | 5 | Use `element.classList.toggle()` to toggle the specified class for the element. 6 | 7 | ```js 8 | const toggleClass = (el, className) => el.classList.toggle(className); 9 | ``` 10 | 11 | ```js 12 | toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore 13 | ``` 14 | -------------------------------------------------------------------------------- /test/cleanObj.test.js: -------------------------------------------------------------------------------- 1 | const {cleanObj} = require('./_30s.js'); 2 | 3 | test('cleanObj is a Function', () => { 4 | expect(cleanObj).toBeInstanceOf(Function); 5 | }); 6 | const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; 7 | test('Removes any properties except the ones specified from a JSON object', () => { 8 | expect(cleanObj(testObj, ['a'], 'children')).toEqual({ a: 1, children: { a: 1 } }); 9 | }); 10 | -------------------------------------------------------------------------------- /test/compact.test.js: -------------------------------------------------------------------------------- 1 | const {compact} = require('./_30s.js'); 2 | 3 | test('compact is a Function', () => { 4 | expect(compact).toBeInstanceOf(Function); 5 | }); 6 | test('Removes falsy values from an array', () => { 7 | expect(compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34, null, undefined])).toEqual([ 8 | 1, 9 | 2, 10 | 3, 11 | 'a', 12 | 's', 13 | 34 14 | ]); 15 | }); 16 | -------------------------------------------------------------------------------- /test/composeRight.test.js: -------------------------------------------------------------------------------- 1 | const {composeRight} = require('./_30s.js'); 2 | 3 | test('composeRight is a Function', () => { 4 | expect(composeRight).toBeInstanceOf(Function); 5 | }); 6 | const add = (x, y) => x + y; 7 | const square = x => x * x; 8 | const addAndSquare = composeRight(add, square); 9 | test('Performs left-to-right function composition', () => { 10 | expect(addAndSquare(1, 2)).toBe(9); 11 | }); 12 | -------------------------------------------------------------------------------- /test/when.test.js: -------------------------------------------------------------------------------- 1 | const {when} = require('./_30s.js'); 2 | 3 | test('when is a Function', () => { 4 | expect(when).toBeInstanceOf(Function); 5 | }); 6 | const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2); 7 | test('Returns the proper result', () => { 8 | expect(doubleEvenNumbers(2)).toBe(4); 9 | }); 10 | test('Returns the proper result', () => { 11 | expect(doubleEvenNumbers(1)).toBe(1); 12 | }); 13 | -------------------------------------------------------------------------------- /test/compose.test.js: -------------------------------------------------------------------------------- 1 | const {compose} = require('./_30s.js'); 2 | 3 | test('compose is a Function', () => { 4 | expect(compose).toBeInstanceOf(Function); 5 | }); 6 | const add5 = x => x + 5; 7 | const multiply = (x, y) => x * y; 8 | const multiplyAndAdd5 = compose( 9 | add5, 10 | multiply 11 | ); 12 | test('Performs right-to-left function composition', () => { 13 | expect(multiplyAndAdd5(5, 2)).toBe(15); 14 | }); 15 | -------------------------------------------------------------------------------- /test/countBy.test.js: -------------------------------------------------------------------------------- 1 | const {countBy} = require('./_30s.js'); 2 | 3 | test('countBy is a Function', () => { 4 | expect(countBy).toBeInstanceOf(Function); 5 | }); 6 | test('Works for functions', () => { 7 | expect(countBy([6.1, 4.2, 6.3], Math.floor)).toEqual({ 4: 1, 6: 2 }); 8 | }); 9 | test('Works for property names', () => { 10 | expect(countBy(['one', 'two', 'three'], 'length')).toEqual({ 3: 2, 5: 1 }); 11 | }); 12 | -------------------------------------------------------------------------------- /test/decapitalize.test.js: -------------------------------------------------------------------------------- 1 | const {decapitalize} = require('./_30s.js'); 2 | 3 | test('decapitalize is a Function', () => { 4 | expect(decapitalize).toBeInstanceOf(Function); 5 | }); 6 | test('Works with default parameter', () => { 7 | expect(decapitalize('FooBar')).toBe('fooBar'); 8 | }); 9 | test('Works with second parameter set to true', () => { 10 | expect(decapitalize('FooBar', true)).toBe('fOOBAR'); 11 | }); 12 | -------------------------------------------------------------------------------- /test/overArgs.test.js: -------------------------------------------------------------------------------- 1 | const {overArgs} = require('./_30s.js'); 2 | 3 | test('overArgs is a Function', () => { 4 | expect(overArgs).toBeInstanceOf(Function); 5 | }); 6 | const square = n => n * n; 7 | const double = n => n * 2; 8 | const fn = overArgs((x, y) => [x, y], [square, double]); 9 | test('Invokes the provided function with its arguments transformed', () => { 10 | expect(fn(9, 3)).toEqual([81, 6]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/partialRight.test.js: -------------------------------------------------------------------------------- 1 | const {partialRight} = require('./_30s.js'); 2 | 3 | test('partialRight is a Function', () => { 4 | expect(partialRight).toBeInstanceOf(Function); 5 | }); 6 | function greet(greeting, name) { 7 | return greeting + ' ' + name + '!'; 8 | } 9 | const greetJohn = partialRight(greet, 'John'); 10 | test('Appends arguments', () => { 11 | expect(greetJohn('Hello')).toBe('Hello John!'); 12 | }); 13 | -------------------------------------------------------------------------------- /test/splitLines.test.js: -------------------------------------------------------------------------------- 1 | const {splitLines} = require('./_30s.js'); 2 | 3 | test('splitLines is a Function', () => { 4 | expect(splitLines).toBeInstanceOf(Function); 5 | }); 6 | test('Splits a multiline string into an array of lines.', () => { 7 | expect(splitLines('This\nis a\nmultiline\nstring.\n')).toEqual([ 8 | 'This', 9 | 'is a', 10 | 'multiline', 11 | 'string.', 12 | '' 13 | ]); 14 | }); 15 | -------------------------------------------------------------------------------- /test/sumBy.test.js: -------------------------------------------------------------------------------- 1 | const {sumBy} = require('./_30s.js'); 2 | 3 | test('sumBy is a Function', () => { 4 | expect(sumBy).toBeInstanceOf(Function); 5 | }); 6 | test('Works with a callback.', () => { 7 | expect(sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n)).toBe(20); 8 | }); 9 | test('Works with a property name.', () => { 10 | expect(sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n')).toBe(20); 11 | }); 12 | -------------------------------------------------------------------------------- /snippets/isBrowserTabFocused.md: -------------------------------------------------------------------------------- 1 | ### isBrowserTabFocused 2 | 3 | Returns `true` if the browser tab of the page is focused, `false` otherwise. 4 | 5 | Use the `Document.hidden` property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden. 6 | 7 | ```js 8 | const isBrowserTabFocused = () => !document.hidden; 9 | ``` 10 | 11 | ```js 12 | isBrowserTabFocused(); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/last.md: -------------------------------------------------------------------------------- 1 | ### last 2 | 3 | ------------ 4 | 5 | Returns the last element in an array. 6 | 7 | Use `arr.length - 1` to compute the index of the last element of the given array and returning it. 8 | 9 | ------------ 10 | 11 | 返回数组中的最后一个元素。 12 | 13 | 使用 `arr.length - 1` 来计算给定数组的最后一个元素的索引并返回。 14 | 15 | ```js 16 | const last = arr => arr[arr.length - 1]; 17 | ``` 18 | 19 | ```js 20 | last([1, 2, 3]); // 3 21 | ``` 22 | -------------------------------------------------------------------------------- /snippets/objectToPairs.md: -------------------------------------------------------------------------------- 1 | ### objectToPairs 2 | 3 | Creates an array of key-value pair arrays from an object. 4 | 5 | Use `Object.keys()` and `Array.prototype.map()` to iterate over the object's keys and produce an array with key-value pairs. 6 | 7 | ```js 8 | const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]); 9 | ``` 10 | 11 | ```js 12 | objectToPairs({ a: 1, b: 2 }); // [ ['a', 1], ['b', 2] ] 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/reverseString.md: -------------------------------------------------------------------------------- 1 | ### reverseString 2 | 3 | Reverses a string. 4 | 5 | Use the spread operator (`...`) and `Array.prototype.reverse()` to reverse the order of the characters in the string. 6 | Combine characters to get a string using `String.prototype.join('')`. 7 | 8 | ```js 9 | const reverseString = str => [...str].reverse().join(''); 10 | ``` 11 | 12 | ```js 13 | reverseString('foobar'); // 'raboof' 14 | ``` 15 | -------------------------------------------------------------------------------- /test/insertAfter.test.js: -------------------------------------------------------------------------------- 1 | const {insertAfter} = require('./_30s.js'); 2 | 3 | test('insertAfter is a Function', () => { 4 | expect(insertAfter).toBeInstanceOf(Function); 5 | }); 6 | let e = document.createElement('div'); 7 | e.setAttribute('id', 'test'); 8 | test('Does not throw error if the element exists', () => { 9 | expect(() => { 10 | insertAfter(e, 'test'); 11 | }).not.toThrow(TypeError); 12 | }); 13 | -------------------------------------------------------------------------------- /test/isArmstrongNumber.test.js: -------------------------------------------------------------------------------- 1 | const {isArmstrongNumber} = require('./_30s.js'); 2 | 3 | test('isArmstrongNumber is a Function', () => { 4 | expect(isArmstrongNumber).toBeInstanceOf(Function); 5 | }); 6 | test('isArmstrongNumber returns true', () => { 7 | expect(isArmstrongNumber(1634)).toBeTruthy(); 8 | }); 9 | test('isArmstrongNumber returns false', () => { 10 | expect(isArmstrongNumber(56)).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/once.test.js: -------------------------------------------------------------------------------- 1 | const {once} = require('./_30s.js'); 2 | 3 | test('once is a Function', () => { 4 | expect(once).toBeInstanceOf(Function); 5 | }); 6 | test('once returns Function', () => { 7 | expect(typeof once(x => 10)).toBe('function'); 8 | }); 9 | test('once returns the result only once', () => { 10 | let onced = once(x => x); 11 | expect(onced(10)).toBe(10); 12 | expect(onced(10)).toBe(undefined); 13 | }); 14 | -------------------------------------------------------------------------------- /snippets/getColonTimeFromDate.md: -------------------------------------------------------------------------------- 1 | ### getColonTimeFromDate 2 | 3 | Returns a string of the form `HH:MM:SS` from a `Date` object. 4 | 5 | Use `Date.prototype.toTimeString()` and `String.prototype.slice()` to get the `HH:MM:SS` part of a given `Date` object. 6 | 7 | ```js 8 | const getColonTimeFromDate = date => date.toTimeString().slice(0, 8); 9 | ``` 10 | 11 | ```js 12 | getColonTimeFromDate(new Date()); // "08:38:00" 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/randomIntegerInRange.md: -------------------------------------------------------------------------------- 1 | ### randomIntegerInRange 2 | 3 | Returns a random integer in the specified range. 4 | 5 | Use `Math.random()` to generate a random number and map it to the desired range, using `Math.floor()` to make it an integer. 6 | 7 | ```js 8 | const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; 9 | ``` 10 | 11 | ```js 12 | randomIntegerInRange(0, 5); // 2 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/round.md: -------------------------------------------------------------------------------- 1 | ### round 2 | 3 | Rounds a number to a specified amount of digits. 4 | 5 | Use `Math.round()` and template literals to round the number to the specified number of digits. 6 | Omit the second argument, `decimals` to round to an integer. 7 | 8 | ```js 9 | const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`); 10 | ``` 11 | 12 | ```js 13 | round(1.005, 2); // 1.01 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/untildify.md: -------------------------------------------------------------------------------- 1 | ### untildify 2 | 3 | Converts a tilde path to an absolute path. 4 | 5 | Use `String.prototype.replace()` with a regular expression and `OS.homedir()` to replace the `~` in the start of the path with the home directory. 6 | 7 | ```js 8 | const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$1`); 9 | ``` 10 | 11 | ```js 12 | untildify('~/node'); // '/Users/aUser/node' 13 | ``` 14 | -------------------------------------------------------------------------------- /test/coalesceFactory.test.js: -------------------------------------------------------------------------------- 1 | const {coalesceFactory} = require('./_30s.js'); 2 | 3 | test('coalesceFactory is a Function', () => { 4 | expect(coalesceFactory).toBeInstanceOf(Function); 5 | }); 6 | const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); 7 | test('Returns a customized coalesce function', () => { 8 | expect(customCoalesce(undefined, null, NaN, '', 'Waldo')).toEqual('Waldo'); 9 | }); 10 | -------------------------------------------------------------------------------- /test/extendHex.test.js: -------------------------------------------------------------------------------- 1 | const {extendHex} = require('./_30s.js'); 2 | 3 | test('extendHex is a Function', () => { 4 | expect(extendHex).toBeInstanceOf(Function); 5 | }); 6 | test('Extends a 3-digit color code to a 6-digit color code', () => { 7 | expect(extendHex('#03f')).toBe('#0033ff'); 8 | }); 9 | test('Extends a 3-digit color code to a 6-digit color code', () => { 10 | expect(extendHex('05a')).toBe('#0055aa'); 11 | }); 12 | -------------------------------------------------------------------------------- /test/gcd.test.js: -------------------------------------------------------------------------------- 1 | const {gcd} = require('./_30s.js'); 2 | 3 | test('gcd is a Function', () => { 4 | expect(gcd).toBeInstanceOf(Function); 5 | }); 6 | test('Calculates the greatest common divisor between two or more numbers/arrays', () => { 7 | expect(gcd(8, 36)).toBe(4); 8 | }); 9 | test('Calculates the greatest common divisor between two or more numbers/arrays', () => { 10 | expect(gcd(...[12, 8, 32])).toEqual(4); 11 | }); 12 | -------------------------------------------------------------------------------- /test/hashNode.test.js: -------------------------------------------------------------------------------- 1 | const {hashNode} = require('./_30s.js'); 2 | 3 | test('hashNode is a Function', () => { 4 | expect(hashNode).toBeInstanceOf(Function); 5 | }); 6 | test("Produces the appropriate hash", () => { 7 | expect( 8 | hashNode(JSON.stringify({ a: "a", b: [1, 2, 3, 4], foo: { c: "bar" } })) 9 | ).resolves.toBe( 10 | "04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393" 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /test/indexOfAll.test.js: -------------------------------------------------------------------------------- 1 | const {indexOfAll} = require('./_30s.js'); 2 | 3 | test('indexOfAll is a Function', () => { 4 | expect(indexOfAll).toBeInstanceOf(Function); 5 | }); 6 | test('Returns all indices of val in an array', () => { 7 | expect(indexOfAll([1, 2, 3, 1, 2, 3], 1)).toEqual([0, 3]); 8 | }); 9 | test('When val is not found, return an empty array', () => { 10 | expect(indexOfAll([1, 2, 3], 4)).toEqual([]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/insertBefore.test.js: -------------------------------------------------------------------------------- 1 | const {insertBefore} = require('./_30s.js'); 2 | 3 | test('insertBefore is a Function', () => { 4 | expect(insertBefore).toBeInstanceOf(Function); 5 | }); 6 | let e = document.createElement('div'); 7 | e.setAttribute('id', 'test'); 8 | test('Does not throw error if the element exists', () => { 9 | expect(() => { 10 | insertBefore(e, 'test'); 11 | }).not.toThrow(TypeError); 12 | }); 13 | -------------------------------------------------------------------------------- /test/pipeFunctions.test.js: -------------------------------------------------------------------------------- 1 | const {pipeFunctions} = require('./_30s.js'); 2 | 3 | test('pipeFunctions is a Function', () => { 4 | expect(pipeFunctions).toBeInstanceOf(Function); 5 | }); 6 | const add5 = x => x + 5; 7 | const multiply = (x, y) => x * y; 8 | const multiplyAndAdd5 = pipeFunctions(multiply, add5); 9 | test('Performs left-to-right function composition', () => { 10 | expect(multiplyAndAdd5(5, 2)).toBe(15); 11 | }); 12 | -------------------------------------------------------------------------------- /test/shallowClone.test.js: -------------------------------------------------------------------------------- 1 | const {shallowClone} = require('./_30s.js'); 2 | 3 | test('shallowClone is a Function', () => { 4 | expect(shallowClone).toBeInstanceOf(Function); 5 | }); 6 | const a = { foo: 'bar', obj: { a: 1, b: 2 } }; 7 | const b = shallowClone(a); 8 | test('Shallow cloning works', () => { 9 | expect(a).not.toBe(b); 10 | }); 11 | test('Does not clone deeply', () => { 12 | expect(a.obj).toBe(b.obj); 13 | }); 14 | -------------------------------------------------------------------------------- /snippets/initial.md: -------------------------------------------------------------------------------- 1 | ### initial 2 | 3 | ------------ 4 | 5 | Returns all the elements of an array except the last one. 6 | 7 | Use `arr.slice(0,-1)` to return all but the last element of the array. 8 | 9 | ------------ 10 | 11 | 返回数组中除最后一个元素外的所有元素。 12 | 13 | 使用 `arr.slice(0,-1)` 返回数组中除最后一个元素外的所有元素。 14 | 15 | ```js 16 | const initial = arr => arr.slice(0, -1); 17 | ``` 18 | 19 | ```js 20 | initial([1, 2, 3]); // [1,2] 21 | ``` 22 | -------------------------------------------------------------------------------- /snippets/isObjectLike.md: -------------------------------------------------------------------------------- 1 | ### isObjectLike 2 | 3 | Checks if a value is object-like. 4 | 5 | Check if the provided value is not `null` and its `typeof` is equal to `'object'`. 6 | 7 | ```js 8 | const isObjectLike = val => val !== null && typeof val === 'object'; 9 | ``` 10 | 11 | ```js 12 | isObjectLike({}); // true 13 | isObjectLike([1, 2, 3]); // true 14 | isObjectLike(x => x); // false 15 | isObjectLike(null); // false 16 | ``` 17 | -------------------------------------------------------------------------------- /snippets/isSameDate.md: -------------------------------------------------------------------------------- 1 | ### isSameDate 2 | 3 | Check if a date is the same as another date. 4 | 5 | Use `Date.prototype.toISOString()` and strict equality checking (`===`) to check if the first date is the same as the second one. 6 | 7 | ```js 8 | const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString(); 9 | ``` 10 | 11 | ```js 12 | isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true 13 | ``` 14 | -------------------------------------------------------------------------------- /test/getURLParameters.test.js: -------------------------------------------------------------------------------- 1 | const {getURLParameters} = require('./_30s.js'); 2 | 3 | test('getURLParameters is a Function', () => { 4 | expect(getURLParameters).toBeInstanceOf(Function); 5 | }); 6 | test('Returns an object containing the parameters of the current URL', () => { 7 | expect(getURLParameters('http://url.com/page?name=Adam&surname=Smith')).toEqual({ 8 | name: 'Adam', 9 | surname: 'Smith' 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /test/isPlainObject.test.js: -------------------------------------------------------------------------------- 1 | const {isPlainObject} = require('./_30s.js'); 2 | 3 | test('isPlainObject is a Function', () => { 4 | expect(isPlainObject).toBeInstanceOf(Function); 5 | }); 6 | test('Returns true for a plain object', () => { 7 | expect(isPlainObject({ a: 1 })).toBeTruthy(); 8 | }); 9 | test('Returns false for a Map (example of non-plain object)', () => { 10 | expect(isPlainObject(new Map())).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/toHash.test.js: -------------------------------------------------------------------------------- 1 | const {toHash} = require('./_30s.js'); 2 | 3 | test('toHash is a Function', () => { 4 | expect(toHash).toBeInstanceOf(Function); 5 | }); 6 | test('toHash works properly with indexes', () => { 7 | expect(toHash([4, 3, 2, 1])).toEqual({ 0: 4, 1: 3, 2: 2, 3: 1 }); 8 | }); 9 | test('toHash works properly with keys', () => { 10 | expect(toHash([{ a: 'label' }], 'a')).toEqual({ label: { a: 'label' } }); 11 | }); 12 | -------------------------------------------------------------------------------- /snippets/isWeekday.md: -------------------------------------------------------------------------------- 1 | ### isWeekday 2 | 3 | Results in a boolean representation of a specific date. 4 | 5 | Pass the specific date object firstly. 6 | Use `Date.getDay()` to check weekday by using a modulo operator and then returning a boolean. 7 | 8 | ```js 9 | const isWeekday = (t = new Date()) => { 10 | return t.getDay() % 6 !== 0; 11 | }; 12 | ``` 13 | 14 | ```js 15 | isWeekday(); // true (if current date is 2019-07-19) 16 | ``` 17 | -------------------------------------------------------------------------------- /snippets/powerset.md: -------------------------------------------------------------------------------- 1 | ### powerset 2 | 3 | Returns the powerset of a given array of numbers. 4 | 5 | Use `Array.prototype.reduce()` combined with `Array.prototype.map()` to iterate over elements and combine into an array containing all combinations. 6 | 7 | ```js 8 | const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]); 9 | ``` 10 | 11 | ```js 12 | powerset([1, 2]); // [[], [1], [2], [2, 1]] 13 | ``` 14 | -------------------------------------------------------------------------------- /test/indentString.test.js: -------------------------------------------------------------------------------- 1 | const {indentString} = require('./_30s.js'); 2 | 3 | test('indentString is a Function', () => { 4 | expect(indentString).toBeInstanceOf(Function); 5 | }); 6 | test('indentString is a Function', () => { 7 | expect(indentString('Lorem\nIpsum', 2)).toBe(' Lorem\n Ipsum'); 8 | }); 9 | test('indentString is a Function', () => { 10 | expect(indentString('Lorem\nIpsum', 2, '_')).toBe('__Lorem\n__Ipsum'); 11 | }); 12 | -------------------------------------------------------------------------------- /test/maxDate.test.js: -------------------------------------------------------------------------------- 1 | const {maxDate} = require('./_30s.js'); 2 | 3 | test('maxDate is a Function', () => { 4 | expect(maxDate).toBeInstanceOf(Function); 5 | }); 6 | test('maxDate produces the maximum date', () => { 7 | const array = [ 8 | new Date(2017, 4, 13), 9 | new Date(2018, 2, 12), 10 | new Date(2016, 0, 10), 11 | new Date(2016, 0, 9) 12 | ]; 13 | expect(maxDate(array)).toEqual(new Date(2018, 2, 12)); 14 | }); 15 | -------------------------------------------------------------------------------- /test/minDate.test.js: -------------------------------------------------------------------------------- 1 | const {minDate} = require('./_30s.js'); 2 | 3 | test('minDate is a Function', () => { 4 | expect(minDate).toBeInstanceOf(Function); 5 | }); 6 | test('minDate produces the minimum date', () => { 7 | const array = [ 8 | new Date(2017, 4, 13), 9 | new Date(2018, 2, 12), 10 | new Date(2016, 0, 10), 11 | new Date(2016, 0, 9) 12 | ]; 13 | expect(minDate(array)).toEqual(new Date(2016, 0, 9)); 14 | }); 15 | -------------------------------------------------------------------------------- /test/takeRight.test.js: -------------------------------------------------------------------------------- 1 | const {takeRight} = require('./_30s.js'); 2 | 3 | test('takeRight is a Function', () => { 4 | expect(takeRight).toBeInstanceOf(Function); 5 | }); 6 | test('Returns an array with n elements removed from the end', () => { 7 | expect(takeRight([1, 2, 3], 2)).toEqual([2, 3]); 8 | }); 9 | test('Returns an array with n elements removed from the end', () => { 10 | expect(takeRight([1, 2, 3])).toEqual([3]); 11 | }); 12 | -------------------------------------------------------------------------------- /snippets/getDaysDiffBetweenDates.md: -------------------------------------------------------------------------------- 1 | ### getDaysDiffBetweenDates 2 | 3 | Returns the difference (in days) between two dates. 4 | 5 | Calculate the difference (in days) between two `Date` objects. 6 | 7 | ```js 8 | const getDaysDiffBetweenDates = (dateInitial, dateFinal) => 9 | (dateFinal - dateInitial) / (1000 * 3600 * 24); 10 | ``` 11 | 12 | ```js 13 | getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/setStyle.md: -------------------------------------------------------------------------------- 1 | ### setStyle 2 | 3 | Sets the value of a CSS rule for the specified element. 4 | 5 | Use `element.style` to set the value of the CSS rule for the specified element to `val`. 6 | 7 | ```js 8 | const setStyle = (el, ruleName, val) => (el.style[ruleName] = val); 9 | ``` 10 | 11 | ```js 12 | setStyle(document.querySelector('p'), 'font-size', '20px'); // The first

element on the page will have a font-size of 20px 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets_archive/squareSum.md: -------------------------------------------------------------------------------- 1 | ### squareSum 2 | 3 | Squares each number in an array and then sums the results together. 4 | 5 | Use `Array.prototype.reduce()` in combination with `Math.pow()` to iterate over numbers and sum their squares into an accumulator. 6 | 7 | ```js 8 | const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0); 9 | ``` 10 | 11 | ```js 12 | squareSum(1, 2, 2); // 9 13 | ``` 14 | -------------------------------------------------------------------------------- /test/isNil.test.js: -------------------------------------------------------------------------------- 1 | const {isNil} = require('./_30s.js'); 2 | 3 | test('isNil is a Function', () => { 4 | expect(isNil).toBeInstanceOf(Function); 5 | }); 6 | test('Returns true for null', () => { 7 | expect(isNil(null)).toBeTruthy(); 8 | }); 9 | test('Returns true for undefined', () => { 10 | expect(isNil(undefined)).toBeTruthy(); 11 | }); 12 | test('Returns false for an empty string', () => { 13 | expect(isNil('')).toBeFalsy(); 14 | }); 15 | -------------------------------------------------------------------------------- /test/runPromisesInSeries.test.js: -------------------------------------------------------------------------------- 1 | const {runPromisesInSeries} = require('./_30s.js'); 2 | 3 | test('runPromisesInSeries is a Function', () => { 4 | expect(runPromisesInSeries).toBeInstanceOf(Function); 5 | }); 6 | const delay = d => new Promise(r => setTimeout(r, d)); 7 | test('Runs promises in series', () => { 8 | return runPromisesInSeries([() => delay(100), () => delay(200)]).then(() => 9 | expect(true).toBeTruthy() 10 | ); 11 | }); 12 | -------------------------------------------------------------------------------- /glossary/Recursion.md: -------------------------------------------------------------------------------- 1 | ### Recursion 2 | 3 | Recursion is the repeated application of a process. 4 | In JavaScript, recursion involves functions that call themselves repeatedly until they reach a base condition. 5 | The base condition breaks out of the recursion loop because otherwise the function would call itself indefinitely. 6 | Recursion is very useful when working with nested data, especially when the nesting depth is dynamically defined or unkown. 7 | -------------------------------------------------------------------------------- /test/bind.test.js: -------------------------------------------------------------------------------- 1 | const {bind} = require('./_30s.js'); 2 | 3 | test('bind is a Function', () => { 4 | expect(bind).toBeInstanceOf(Function); 5 | }); 6 | function greet(greeting, punctuation) { 7 | return greeting + ' ' + this.user + punctuation; 8 | } 9 | const freddy = { user: 'fred' }; 10 | const freddyBound = bind(greet, freddy); 11 | test('Binds to an object context', () => { 12 | expect(freddyBound('hi', '!')).toBe('hi fred!'); 13 | }); 14 | -------------------------------------------------------------------------------- /test/isTravisCI.test.js: -------------------------------------------------------------------------------- 1 | const {isTravisCI} = require('./_30s.js'); 2 | 3 | test('isTravisCI is a Function', () => { 4 | expect(isTravisCI).toBeInstanceOf(Function); 5 | }); 6 | if (isTravisCI()) { 7 | test('Running on Travis, correctly evaluates', () => { 8 | expect(isTravisCI()).toBeTruthy(); 9 | }); 10 | } else { 11 | test('Not running on Travis, correctly evaluates', () => { 12 | expect(isTravisCI()).toBeFalsy(); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /test/symmetricDifferenceBy.test.js: -------------------------------------------------------------------------------- 1 | const {symmetricDifferenceBy} = require('./_30s.js'); 2 | 3 | test('symmetricDifferenceBy is a Function', () => { 4 | expect(symmetricDifferenceBy).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the symmetric difference between two arrays, after applying the provided function to each array element of both', () => { 7 | expect(symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual([1.2, 3.4]); 8 | }); 9 | -------------------------------------------------------------------------------- /test/unzipWith.test.js: -------------------------------------------------------------------------------- 1 | const {unzipWith} = require('./_30s.js'); 2 | 3 | test('unzipWith is a Function', () => { 4 | expect(unzipWith).toBeInstanceOf(Function); 5 | }); 6 | test('unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) equals [3, 30, 300]', () => { 7 | expect( 8 | unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) 9 | ).toEqual([3, 30, 300]); 10 | }); 11 | -------------------------------------------------------------------------------- /glossary/ShadowDOM.md: -------------------------------------------------------------------------------- 1 | ### Shadow DOM 2 | 3 | Shadow DOM allows you to attach hidden DOM trees to elements in the normal DOM tree, which are included in the document rendering, but excluded from the main document DOM tree. 4 | A shadow DOM tree will start with a shadow root, to which you can attach any elements you want, just like in a regular DOM. 5 | Examples of shadow DOM uses are the `

after

'); //
...

after

13 | ``` 14 | -------------------------------------------------------------------------------- /test/bindKey.test.js: -------------------------------------------------------------------------------- 1 | const {bindKey} = require('./_30s.js'); 2 | 3 | test('bindKey is a Function', () => { 4 | expect(bindKey).toBeInstanceOf(Function); 5 | }); 6 | const freddy = { 7 | user: 'fred', 8 | greet(greeting, punctuation) { 9 | return greeting + ' ' + this.user + punctuation; 10 | } 11 | }; 12 | const freddyBound = bindKey(freddy, 'greet'); 13 | test('Binds function to an object context', () => { 14 | expect(freddyBound('hi', '!')).toBe('hi fred!'); 15 | }); 16 | -------------------------------------------------------------------------------- /test/isArrayLike.test.js: -------------------------------------------------------------------------------- 1 | const {isArrayLike} = require('./_30s.js'); 2 | 3 | test('isArrayLike is a Function', () => { 4 | expect(isArrayLike).toBeInstanceOf(Function); 5 | }); 6 | test('Returns true for a string', () => { 7 | expect(isArrayLike('abc')).toBeTruthy(); 8 | }); 9 | test('Returns true for an array', () => { 10 | expect(isArrayLike([1, 2, 3])).toBeTruthy(); 11 | }); 12 | test('Returns false for null', () => { 13 | expect(isArrayLike(null)).toBeFalsy(); 14 | }); 15 | -------------------------------------------------------------------------------- /snippets/nthArg.md: -------------------------------------------------------------------------------- 1 | ### nthArg 2 | 3 | Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned. 4 | 5 | Use `Array.prototype.slice()` to get the desired argument at index `n`. 6 | 7 | ```js 8 | const nthArg = n => (...args) => args.slice(n)[0]; 9 | ``` 10 | 11 | ```js 12 | const third = nthArg(2); 13 | third(1, 2, 3); // 3 14 | third(1, 2); // undefined 15 | const last = nthArg(-1); 16 | last(1, 2, 3, 4, 5); // 5 17 | ``` 18 | -------------------------------------------------------------------------------- /snippets/sortCharactersInString.md: -------------------------------------------------------------------------------- 1 | ### sortCharactersInString 2 | 3 | Alphabetically sorts the characters in a string. 4 | 5 | Use the spread operator (`...`), `Array.prototype.sort()` and `String.localeCompare()` to sort the characters in `str`, recombine using `String.prototype.join('')`. 6 | 7 | ```js 8 | const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b)).join(''); 9 | ``` 10 | 11 | ```js 12 | sortCharactersInString('cabbage'); // 'aabbceg' 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/when.md: -------------------------------------------------------------------------------- 1 | ### when 2 | 3 | Tests a value, `x`, against a predicate function. If `true`, return `fn(x)`. Else, return `x`. 4 | 5 | Return a function expecting a single value, `x`, that returns the appropriate value based on `pred`. 6 | 7 | ```js 8 | const when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x); 9 | ``` 10 | 11 | ```js 12 | const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2); 13 | doubleEvenNumbers(2); // 4 14 | doubleEvenNumbers(1); // 1 15 | ``` 16 | -------------------------------------------------------------------------------- /test/countOccurrences.test.js: -------------------------------------------------------------------------------- 1 | const {countOccurrences} = require('./_30s.js'); 2 | 3 | test('countOccurrences is a Function', () => { 4 | expect(countOccurrences).toBeInstanceOf(Function); 5 | }); 6 | test('Counts the occurrences of a value in an array', () => { 7 | expect(countOccurrences([1, 1, 2, 1, 2, 3], 1)).toEqual(3); 8 | }); 9 | test('Works with different types in the same array', () => { 10 | expect(countOccurrences([1, 1, 2, 1, 2, 3, '1', true], 1)).toEqual(3); 11 | }); 12 | -------------------------------------------------------------------------------- /test/getType.test.js: -------------------------------------------------------------------------------- 1 | const {getType} = require('./_30s.js'); 2 | 3 | test('getType is a Function', () => { 4 | expect(getType).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the native type of a value', () => { 7 | expect(getType(new Set([1, 2, 3]))).toBe('set'); 8 | }); 9 | test('Returns null for null', () => { 10 | expect(getType(null)).toBe('null'); 11 | }); 12 | test('Returns undefined for undefined', () => { 13 | expect(getType(undefined)).toBe('undefined'); 14 | }); 15 | -------------------------------------------------------------------------------- /test/initializeNDArray.test.js: -------------------------------------------------------------------------------- 1 | const {initializeNDArray} = require('./_30s.js'); 2 | 3 | test('initializeNDArray is a Function', () => { 4 | expect(initializeNDArray).toBeInstanceOf(Function); 5 | }); 6 | test('Initializes a n-D array with given data', () => { 7 | expect(initializeNDArray(1, 3)).toEqual([1, 1, 1]); 8 | }); 9 | test('Initializes a n-D array with given data', () => { 10 | expect(initializeNDArray(5, 2, 2, 2)).toEqual([[[5, 5], [5, 5]], [[5, 5], [5, 5]]]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/isAfterDate.test.js: -------------------------------------------------------------------------------- 1 | const {isAfterDate} = require('./_30s.js'); 2 | 3 | test('isAfterDate is a Function', () => { 4 | expect(isAfterDate).toBeInstanceOf(Function); 5 | }); 6 | test('isAfterDate produces the correct result', () => { 7 | expect(isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20))).toBeTruthy(); 8 | }); 9 | test('isBeforeDate produces the correct result', () => { 10 | expect(isAfterDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeFalsy(); 11 | }); 12 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | snippet-template.md 2 | tag_database 3 | travis.log 4 | CONTRIBUTING.md 5 | COLLABORATING.md 6 | CODE_OF_CONDUCT.md 7 | .travis.yml 8 | .mdlrc.style.rb 9 | .mdlrc 10 | .codeclimate.yml 11 | test/* 12 | glossary/* 13 | snippets/* 14 | static-parts/* 15 | snippet_data/* 16 | snippets_archive/* 17 | scripts/* 18 | locale/* 19 | coverage/* 20 | docs/* 21 | .travis/* 22 | .github/* 23 | advanced.svg 24 | package-lock.json 25 | yarn.lock 26 | advanced.svg 27 | sponsored_by_DigitalOcean.png 28 | -------------------------------------------------------------------------------- /snippets/hammingDistance.md: -------------------------------------------------------------------------------- 1 | ### hammingDistance 2 | 3 | Calculates the Hamming distance between two values. 4 | 5 | Use XOR operator (`^`) to find the bit difference between the two numbers, convert to a binary string using `toString(2)`. 6 | Count and return the number of `1`s in the string, using `match(/1/g)`. 7 | 8 | ```js 9 | const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length; 10 | ``` 11 | 12 | ```js 13 | hammingDistance(2, 3); // 1 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/isArrayLike.md: -------------------------------------------------------------------------------- 1 | ### isArrayLike 2 | 3 | Checks if the provided argument is array-like (i.e. is iterable). 4 | 5 | Check if the provided argument is not `null` and that its `Symbol.iterator` property is a function. 6 | 7 | ```js 8 | const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function'; 9 | ``` 10 | 11 | ```js 12 | isArrayLike(document.querySelectorAll('.className')); // true 13 | isArrayLike('abc'); // true 14 | isArrayLike(null); // false 15 | ``` 16 | -------------------------------------------------------------------------------- /snippets/isTravisCI.md: -------------------------------------------------------------------------------- 1 | ### isTravisCI 2 | 3 | Checks if the current environment is [Travis CI](https://travis-ci.org/). 4 | 5 | Checks if the current environment has the `TRAVIS` and `CI` environment variables ([reference](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)). 6 | 7 | ```js 8 | const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; 9 | ``` 10 | 11 | ```js 12 | isTravisCI(); // true (if code is running on Travis CI) 13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/minDate.md: -------------------------------------------------------------------------------- 1 | ### minDate 2 | 3 | Returns the minimum of the given dates. 4 | 5 | Use the ES6 spread syntax to find the minimum date value, `new Date()` to convert it to a `Date` object. 6 | 7 | ```js 8 | const minDate = dates => new Date(Math.min(...dates)); 9 | ``` 10 | 11 | ```js 12 | const array = [ 13 | new Date(2017, 4, 13), 14 | new Date(2018, 2, 12), 15 | new Date(2016, 0, 10), 16 | new Date(2016, 0, 9) 17 | ]; 18 | minDate(array); // 2016-01-08T22:00:00.000Z 19 | ``` 20 | -------------------------------------------------------------------------------- /snippets/truncateString.md: -------------------------------------------------------------------------------- 1 | ### truncateString 2 | 3 | Truncates a string up to a specified length. 4 | 5 | Determine if the string's `length` is greater than `num`. 6 | Return the string truncated to the desired length, with `'...'` appended to the end or the original string. 7 | 8 | ```js 9 | const truncateString = (str, num) => 10 | str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str; 11 | ``` 12 | 13 | ```js 14 | truncateString('boomerang', 7); // 'boom...' 15 | ``` 16 | -------------------------------------------------------------------------------- /snippets/validateNumber.md: -------------------------------------------------------------------------------- 1 | ### validateNumber 2 | 3 | Returns `true` if the given value is a number, `false` otherwise. 4 | 5 | Use `!isNaN()` in combination with `parseFloat()` to check if the argument is a number. 6 | Use `isFinite()` to check if the number is finite. 7 | Use `Number()` to check if the coercion holds. 8 | 9 | ```js 10 | const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n; 11 | ``` 12 | 13 | ```js 14 | validateNumber('10'); // true 15 | ``` 16 | -------------------------------------------------------------------------------- /test/collectInto.test.js: -------------------------------------------------------------------------------- 1 | const {collectInto} = require('./_30s.js'); 2 | 3 | test('collectInto is a Function', () => { 4 | expect(collectInto).toBeInstanceOf(Function); 5 | }); 6 | const Pall = collectInto(Promise.all.bind(Promise)); 7 | let p1 = Promise.resolve(1); 8 | let p2 = Promise.resolve(2); 9 | let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); 10 | test('Works with multiple promises', () => { 11 | return expect(Pall(p1, p2, p3)).resolves.toEqual([1, 2, 3]); 12 | }); 13 | -------------------------------------------------------------------------------- /test/flattenObject.test.js: -------------------------------------------------------------------------------- 1 | const {flattenObject} = require('./_30s.js'); 2 | 3 | test('flattenObject is a Function', () => { 4 | expect(flattenObject).toBeInstanceOf(Function); 5 | }); 6 | test('Flattens an object with the paths for keys', () => { 7 | expect(flattenObject({ a: { b: { c: 1 } }, d: 1 })).toEqual({ 'a.b.c': 1, d: 1 }); 8 | }); 9 | test('Works with arrays', () => { 10 | expect(flattenObject([0, 1, [2, [1]], 1])).toEqual({ 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 }); 11 | }); 12 | -------------------------------------------------------------------------------- /test/merge.test.js: -------------------------------------------------------------------------------- 1 | const {merge} = require('./_30s.js'); 2 | 3 | test('merge is a Function', () => { 4 | expect(merge).toBeInstanceOf(Function); 5 | }); 6 | const object = { 7 | a: [{ x: 2 }, { y: 4 }], 8 | b: 1 9 | }; 10 | const other = { 11 | a: { z: 3 }, 12 | b: [2, 3], 13 | c: 'foo' 14 | }; 15 | test('Merges two objects', () => { 16 | expect(merge(object, other)).toEqual({ 17 | a: [{ x: 2 }, { y: 4 }, { z: 3 }], 18 | b: [1, 2, 3], 19 | c: 'foo' 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /snippets/byteSize.md: -------------------------------------------------------------------------------- 1 | ### byteSize 2 | 3 | Returns the length of a string in bytes. 4 | 5 | Convert a given string to a [`Blob` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and find its `size`. 6 | 7 | 以字节为单位返回字符串的长度。 8 | 9 | 将给定的字符串转换为[`Blob Object`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)并找到它的`size`。 10 | 11 | ```js 12 | const byteSize = str => new Blob([str]).size; 13 | ``` 14 | 15 | ```js 16 | byteSize('😀'); // 4 17 | byteSize('Hello World'); // 11 18 | ``` 19 | -------------------------------------------------------------------------------- /snippets/cloneRegExp.md: -------------------------------------------------------------------------------- 1 | ### cloneRegExp 2 | 3 | Clones a regular expression. 4 | 5 | Use `new RegExp()`, `RegExp.source` and `RegExp.flags` to clone the given regular expression. 6 | 7 | 克隆一个正则表达式。 8 | 9 | 使用 `new RegExp()` , `RegExp.source` 和 `RegExp.flags` 来克隆给定的正则表达式。 10 | 11 | ```js 12 | const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags); 13 | ``` 14 | 15 | ```js 16 | const regExp = /lorem ipsum/gi; 17 | const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi 18 | ``` 19 | -------------------------------------------------------------------------------- /test/elo.test.js: -------------------------------------------------------------------------------- 1 | const {elo} = require('./_30s.js'); 2 | 3 | test('elo is a Function', () => { 4 | expect(elo).toBeInstanceOf(Function); 5 | }); 6 | test('Standard 1v1s', () => { 7 | expect(elo([1200, 1200])).toEqual([1216, 1184]); 8 | }); 9 | test('Standard 1v1s', () => { 10 | expect(elo([1200, 1200], 64)).toEqual([1232, 1168]); 11 | }); 12 | test('4 player FFA, all same rank', () => { 13 | expect(elo([1200, 1200, 1200, 1200]).map(Math.round)).toEqual([1246, 1215, 1185, 1154]); 14 | }); 15 | -------------------------------------------------------------------------------- /test/findLastKey.test.js: -------------------------------------------------------------------------------- 1 | const {findLastKey} = require('./_30s.js'); 2 | 3 | test('findLastKey is a Function', () => { 4 | expect(findLastKey).toBeInstanceOf(Function); 5 | }); 6 | test('returns the appropriate key', () => { 7 | expect( 8 | findLastKey( 9 | { 10 | barney: { age: 36, active: true }, 11 | fred: { age: 40, active: false }, 12 | pebbles: { age: 1, active: true } 13 | }, 14 | o => o['active'] 15 | ) 16 | ).toBe('pebbles'); 17 | }); 18 | -------------------------------------------------------------------------------- /test/isLowerCase.test.js: -------------------------------------------------------------------------------- 1 | const {isLowerCase} = require('./_30s.js'); 2 | 3 | test('isLowerCase is a Function', () => { 4 | expect(isLowerCase).toBeInstanceOf(Function); 5 | }); 6 | test('passed string is a lowercase', () => { 7 | expect(isLowerCase('abc')).toBeTruthy(); 8 | }); 9 | test('passed string is a lowercase', () => { 10 | expect(isLowerCase('a3@$')).toBeTruthy(); 11 | }); 12 | test('passed value is not a lowercase', () => { 13 | expect(isLowerCase('A3@$')).toBeFalsy(); 14 | }); 15 | -------------------------------------------------------------------------------- /snippets/insertBefore.md: -------------------------------------------------------------------------------- 1 | ### insertBefore 2 | 3 | Inserts an HTML string before the start of the specified element. 4 | 5 | Use `el.insertAdjacentHTML()` with a position of `'beforebegin'` to parse `htmlString` and insert it before the start of `el`. 6 | 7 | ```js 8 | const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', htmlString); 9 | ``` 10 | 11 | ```js 12 | insertBefore(document.getElementById('myId'), '

before

'); //

before

...
13 | ``` 14 | -------------------------------------------------------------------------------- /snippets/isNumber.md: -------------------------------------------------------------------------------- 1 | ### isNumber 2 | 3 | Checks if the given argument is a number. 4 | 5 | Use `typeof` to check if a value is classified as a number primitive. 6 | To safeguard against `NaN`, check if `val === val` (as `NaN` has a `typeof` equal to `number` and is the only value not equal to itself). 7 | 8 | ```js 9 | const isNumber = val => typeof val === 'number' && val === val; 10 | ``` 11 | 12 | ```js 13 | isNumber(1); // true 14 | isNumber('1'); // false 15 | isNumber(NaN); // false 16 | ``` 17 | -------------------------------------------------------------------------------- /snippets/pick.md: -------------------------------------------------------------------------------- 1 | ### pick 2 | 3 | Picks the key-value pairs corresponding to the given keys from an object. 4 | 5 | Use `Array.prototype.reduce()` to convert the filtered/picked keys back to an object with the corresponding key-value pairs if the key exists in the object. 6 | 7 | ```js 8 | const pick = (obj, arr) => 9 | arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {}); 10 | ``` 11 | 12 | ```js 13 | pick({ a: 1, b: '2', c: 3 }, ['a', 'c']); // { 'a': 1, 'c': 3 } 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/randomHexColorCode.md: -------------------------------------------------------------------------------- 1 | ### randomHexColorCode 2 | 3 | Generates a random hexadecimal color code. 4 | 5 | Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`. 6 | 7 | ```js 8 | const randomHexColorCode = () => { 9 | let n = (Math.random() * 0xfffff * 1000000).toString(16); 10 | return '#' + n.slice(0, 6); 11 | }; 12 | ``` 13 | 14 | ```js 15 | randomHexColorCode(); // "#e34155" 16 | ``` 17 | -------------------------------------------------------------------------------- /test/drop.test.js: -------------------------------------------------------------------------------- 1 | const {drop} = require('./_30s.js'); 2 | 3 | test('drop is a Function', () => { 4 | expect(drop).toBeInstanceOf(Function); 5 | }); 6 | test('Works without the last argument', () => { 7 | expect(drop([1, 2, 3])).toEqual([2, 3]); 8 | }); 9 | test('Removes appropriate element count as specified', () => { 10 | expect(drop([1, 2, 3], 2)).toEqual([3]); 11 | }); 12 | test('Empties array given a count greater than length', () => { 13 | expect(drop([1, 2, 3], 42)).toEqual([]); 14 | }); 15 | -------------------------------------------------------------------------------- /test/isBeforeDate.test.js: -------------------------------------------------------------------------------- 1 | const {isBeforeDate} = require('./_30s.js'); 2 | 3 | test('isBeforeDate is a Function', () => { 4 | expect(isBeforeDate).toBeInstanceOf(Function); 5 | }); 6 | test('isBeforeDate produces the correct result', () => { 7 | expect(isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeTruthy(); 8 | }); 9 | test('isBeforeDate produces the correct result', () => { 10 | expect(isBeforeDate(new Date(2010, 10, 21), new Date(2010, 10, 20))).toBeFalsy(); 11 | }); 12 | 13 | -------------------------------------------------------------------------------- /test/squareSum.test.js: -------------------------------------------------------------------------------- 1 | const {squareSum} = require('./_30s.js'); 2 | 3 | test('squareSum is a Function', () => { 4 | expect(squareSum).toBeInstanceOf(Function); 5 | }); 6 | test('squareSum returns the proper result', () => { 7 | expect(squareSum(2, 3, 4)).toBe(29); 8 | }); 9 | 10 | test('works with negative numbers', () => { 11 | expect(squareSum(-2, 3, -4)).toBe(29); 12 | }); 13 | 14 | test('NaN when parameters have text', () => { 15 | expect(squareSum(-2, 3, -4, 'text')).toBe(NaN); 16 | }); 17 | -------------------------------------------------------------------------------- /test/symmetricDifference.test.js: -------------------------------------------------------------------------------- 1 | const {symmetricDifference} = require('./_30s.js'); 2 | 3 | test('symmetricDifference is a Function', () => { 4 | expect(symmetricDifference).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the symmetric difference between two arrays.', () => { 7 | expect(symmetricDifference([1, 2, 3], [1, 2, 4])).toEqual([3, 4]); 8 | }); 9 | test('Returns duplicates from one array', () => { 10 | expect(symmetricDifference([1, 2, 2], [1, 3, 1])).toEqual([2, 2, 3]); 11 | }); 12 | -------------------------------------------------------------------------------- /test/zipWith.test.js: -------------------------------------------------------------------------------- 1 | const {zipWith} = require('./_30s.js'); 2 | 3 | test('zipWith is a Function', () => { 4 | expect(zipWith).toBeInstanceOf(Function); 5 | }); 6 | test('zipWith returns the correct results', () => { 7 | expect(zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c)).toEqual([111, 222]); 8 | }); 9 | test('zipWith returns the correct results if no function is passed', () => { 10 | expect(zipWith([1, 2], [10, 20], [100, 200])).toEqual([[1, 10, 100], [2, 20, 200]]); 11 | }); 12 | -------------------------------------------------------------------------------- /snippets/delay.md: -------------------------------------------------------------------------------- 1 | ### delay 2 | 3 | Invokes the provided function after `wait` milliseconds. 4 | 5 | Use `setTimeout()` to delay execution of `fn`. 6 | Use the spread (`...`) operator to supply the function with an arbitrary number of arguments. 7 | 8 | ```js 9 | const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args); 10 | ``` 11 | 12 | ```js 13 | delay( 14 | function(text) { 15 | console.log(text); 16 | }, 17 | 1000, 18 | 'later' 19 | ); // Logs 'later' after one second. 20 | ``` 21 | -------------------------------------------------------------------------------- /snippets/maxDate.md: -------------------------------------------------------------------------------- 1 | ### maxDate 2 | 3 | Returns the maximum of the given dates. 4 | 5 | Use the ES6 spread syntax with `Math.max` to find the maximum date value, `new Date()` to convert it to a `Date` object. 6 | 7 | ```js 8 | const maxDate = dates => new Date(Math.max(...dates)); 9 | ``` 10 | 11 | ```js 12 | const array = [ 13 | new Date(2017, 4, 13), 14 | new Date(2018, 2, 12), 15 | new Date(2016, 0, 10), 16 | new Date(2016, 0, 9) 17 | ]; 18 | maxDate(array); // 2018-03-11T22:00:00.000Z 19 | ``` 20 | -------------------------------------------------------------------------------- /test/UUIDGeneratorNode.test.js: -------------------------------------------------------------------------------- 1 | const {UUIDGeneratorNode} = require('./_30s.js'); 2 | 3 | test('UUIDGeneratorNode is a Function', () => { 4 | expect(UUIDGeneratorNode).toBeInstanceOf(Function); 5 | }); 6 | const uuid = UUIDGeneratorNode(); 7 | test('Contains dashes in the proper places', () => { 8 | expect([uuid[8], uuid[13], uuid[18], uuid[23]]).toEqual(['-', '-', '-', '-']); 9 | }); 10 | test('Only contains hexadecimal digits', () => { 11 | expect(/^[0-9A-Fa-f-]+$/.test(uuid)).toBeTruthy(); 12 | }); 13 | -------------------------------------------------------------------------------- /test/intersectionWith.test.js: -------------------------------------------------------------------------------- 1 | const {intersectionWith} = require('./_30s.js'); 2 | 3 | test('intersectionWith is a Function', () => { 4 | expect(intersectionWith).toBeInstanceOf(Function); 5 | }); 6 | test('Returns a list of elements that exist in both arrays, using a provided comparator function', () => { 7 | expect( 8 | intersectionWith( 9 | [1, 1.2, 1.5, 3, 0], 10 | [1.9, 3, 0, 3.9], 11 | (a, b) => Math.round(a) === Math.round(b) 12 | ) 13 | ).toEqual([1.5, 3, 0]); 14 | }); 15 | -------------------------------------------------------------------------------- /test/median.test.js: -------------------------------------------------------------------------------- 1 | const {median} = require('./_30s.js'); 2 | 3 | test('median is a Function', () => { 4 | expect(median).toBeInstanceOf(Function); 5 | }); 6 | test('Returns the median of an array of numbers', () => { 7 | expect(median([5, 6, 50, 1, -5])).toBe(5); 8 | }); 9 | test('Returns the median of an array of numbers', () => { 10 | expect(median([1, 2, 3])).toBe(2); 11 | }); 12 | test('Returns the median of an array of numbers', () => { 13 | expect(median([1, 2, 3, 4])).toBe(2.5); 14 | }); 15 | -------------------------------------------------------------------------------- /snippets/drop.md: -------------------------------------------------------------------------------- 1 | ### drop 2 | 3 | ------------ 4 | 5 | Returns a new array with `n` elements removed from the left. 6 | 7 | Use `Array.prototype.slice()` to remove the specified number of elements from the left. 8 | 9 | ------------ 10 | 11 | 返回从左侧开始删除 `n` 个元素的新数组。 12 | 13 | 使用 `Array.prototype.slice()` 从左边删除指定数量的元素。 14 | 15 | ```js 16 | const drop = (arr, n = 1) => arr.slice(n); 17 | ``` 18 | 19 | ```js 20 | drop([1, 2, 3]); // [2,3] 21 | drop([1, 2, 3], 2); // [3] 22 | drop([1, 2, 3], 42); // [] 23 | ``` 24 | -------------------------------------------------------------------------------- /snippets/isPlainObject.md: -------------------------------------------------------------------------------- 1 | ### isPlainObject 2 | 3 | Checks if the provided value is an object created by the Object constructor. 4 | 5 | Check if the provided value is truthy, use `typeof` to check if it is an object and `Object.constructor` to make sure the constructor is equal to `Object`. 6 | 7 | ```js 8 | const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object; 9 | ``` 10 | 11 | ```js 12 | isPlainObject({ a: 1 }); // true 13 | isPlainObject(new Map()); // false 14 | ``` 15 | -------------------------------------------------------------------------------- /snippets/midpoint.md: -------------------------------------------------------------------------------- 1 | ### midpoint 2 | 3 | Calculates the midpoint between two pairs of (x,y) points. 4 | 5 | Destructure the array to get `x1`, `y1`, `x2` and `y2`, calculate the midpoint for each dimension by dividing the sum of the two endpoints by `2`. 6 | 7 | ```js 8 | const midpoint = ([x1, y1], [x2, y2]) => [(x1 + x2) / 2, (y1 + y2) / 2]; 9 | ``` 10 | 11 | ```js 12 | midpoint([2, 2], [4, 4]); // [3, 3] 13 | midpoint([4, 4], [6, 6]); // [5, 5] 14 | midpoint([1, 3], [2, 4]); // [1.5, 3.5] 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /snippets/partial.md: -------------------------------------------------------------------------------- 1 | ### partial 2 | 3 | Creates a function that invokes `fn` with `partials` prepended to the arguments it receives. 4 | 5 | Use the spread operator (`...`) to prepend `partials` to the list of arguments of `fn`. 6 | 7 | ```js 8 | const partial = (fn, ...partials) => (...args) => fn(...partials, ...args); 9 | ``` 10 | 11 | ```js 12 | const greet = (greeting, name) => greeting + ' ' + name + '!'; 13 | const greetHello = partial(greet, 'Hello'); 14 | greetHello('John'); // 'Hello John!' 15 | ``` 16 | -------------------------------------------------------------------------------- /test/functions.test.js: -------------------------------------------------------------------------------- 1 | const {functions} = require('./_30s.js'); 2 | 3 | test('functions is a Function', () => { 4 | expect(functions).toBeInstanceOf(Function); 5 | }); 6 | function Foo() { 7 | this.a = () => 1; 8 | this.b = () => 2; 9 | } 10 | Foo.prototype.c = () => 3; 11 | test('Returns own methods', () => { 12 | expect(functions(new Foo())).toEqual(['a', 'b']); 13 | }); 14 | test('Returns own and inherited methods', () => { 15 | expect(functions(new Foo(), true)).toEqual(['a', 'b', 'c']); 16 | }); 17 | -------------------------------------------------------------------------------- /test/luhnCheck.test.js: -------------------------------------------------------------------------------- 1 | const {luhnCheck} = require('./_30s.js'); 2 | 3 | test('luhnCheck is a Function', () => { 4 | expect(luhnCheck).toBeInstanceOf(Function); 5 | }); 6 | test('validates identification number', () => { 7 | expect(luhnCheck(6011329933655299)).toBeFalsy(); 8 | }); 9 | test('validates identification number', () => { 10 | expect(luhnCheck('4485275742308327')).toBeTruthy(); 11 | }); 12 | test('validates identification number', () => { 13 | expect(luhnCheck(123456789)).toBeFalsy(); 14 | }); 15 | -------------------------------------------------------------------------------- /test/pipeAsyncFunctions.test.js: -------------------------------------------------------------------------------- 1 | const {pipeAsyncFunctions} = require('./_30s.js'); 2 | 3 | test('pipeAsyncFunctions is a Function', () => { 4 | expect(pipeAsyncFunctions).toBeInstanceOf(Function); 5 | }); 6 | test('pipeAsyncFunctions result should be 15', () => { 7 | expect( 8 | pipeAsyncFunctions( 9 | x => x + 1, 10 | x => new Promise(resolve => setTimeout(() => resolve(x + 2), 0)), 11 | x => x + 3, 12 | async x => (await x) + 4 13 | )(5) 14 | ).resolves.toBe(15); 15 | }); 16 | -------------------------------------------------------------------------------- /test/sample.test.js: -------------------------------------------------------------------------------- 1 | const {sample} = require('./_30s.js'); 2 | 3 | test('sample is a Function', () => { 4 | expect(sample).toBeInstanceOf(Function); 5 | }); 6 | const arr = [3, 7, 9, 11]; 7 | test('Returns a random element from the array', () => { 8 | expect(arr.includes(sample(arr))).toBeTruthy(); 9 | }); 10 | test('Works for single-element arrays', () => { 11 | expect(sample([1])).toBe(1); 12 | }); 13 | test('Returns undefined for empty array', () => { 14 | expect(sample([])).toBe(undefined); 15 | }); 16 | -------------------------------------------------------------------------------- /docs/icons/law.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /snippets/filterNonUnique.md: -------------------------------------------------------------------------------- 1 | ### filterNonUnique 2 | 3 | ------------ 4 | 5 | Filters out the non-unique values in an array. 6 | 7 | Use `Array.prototype.filter()` for an array containing only the unique values. 8 | 9 | ------------ 10 | 11 | 过滤掉数组中的非唯一值。 12 | 13 | 使用 `Array.prototype.filter()` 过滤非唯一值后,返回只包含唯一值的数组。 14 | 15 | ```js 16 | const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i)); 17 | ``` 18 | 19 | ```js 20 | filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1, 3, 5] 21 | ``` 22 | -------------------------------------------------------------------------------- /test/nthArg.test.js: -------------------------------------------------------------------------------- 1 | const {nthArg} = require('./_30s.js'); 2 | 3 | test('nthArg is a Function', () => { 4 | expect(nthArg).toBeInstanceOf(Function); 5 | }); 6 | const third = nthArg(2); 7 | test('Returns the nth argument', () => { 8 | expect(third(1, 2, 3)).toBe(3); 9 | }); 10 | test('Returns undefined if arguments too few', () => { 11 | expect(third(1, 2)).toBe(undefined); 12 | }); 13 | const last = nthArg(-1); 14 | test('Works for negative values', () => { 15 | expect(last(1, 2, 3, 4, 5)).toBe(5); 16 | }); 17 | -------------------------------------------------------------------------------- /test/reject.test.js: -------------------------------------------------------------------------------- 1 | const {reject} = require('./_30s.js'); 2 | 3 | test('reject is a Function', () => { 4 | expect(reject).toBeInstanceOf(Function); 5 | }); 6 | const noEvens = reject(x => x % 2 === 0, [1, 2, 3, 4, 5]); 7 | test('Works with numbers', () => { 8 | expect(noEvens).toEqual([1, 3, 5]); 9 | }); 10 | const fourLettersOrLess = reject(word => word.length > 4, ['Apple', 'Pear', 'Kiwi', 'Banana']); 11 | test('Works with strings', () => { 12 | expect(fourLettersOrLess).toEqual(['Pear', 'Kiwi']); 13 | }); 14 | -------------------------------------------------------------------------------- /glossary/DOM.md: -------------------------------------------------------------------------------- 1 | ### DOM 2 | 3 | The DOM (Document Object Model) is a cross-platform API that treats HTML and XML documents as a tree structure consisting of nodes. 4 | These nodes (such as elements and text nodes) are objects that can be programmatically manipulated and any visible changes made to them are reflected live in the document. 5 | In a browser, this API is available to JavaScript where DOM nodes can be manipulated to change their styles, contents, placement in the document, or interacted with through event listeners. 6 | -------------------------------------------------------------------------------- /vscode_snippets/README.md: -------------------------------------------------------------------------------- 1 | # Importing 30-seconds-of-code snippets to VSCode 2 | 3 | 1. Open Visual Studio Code. 4 | 2. Use Ctrl + Shift + P or command + Shift + P to open the Command Palette. 5 | 3. Search for `Preferences: Configure User Snippets` and then `New Global Snippets file...`. 6 | 4. Select a name and save in the default snippets directory. 7 | 5. Copy and paste the content of `snippets.json` from the `vscode_snippets` folder to the file you previously created. -------------------------------------------------------------------------------- /snippets/castArray.md: -------------------------------------------------------------------------------- 1 | ### castArray 2 | 3 | Casts the provided value as an array if it's not one. 4 | 5 | Use `Array.prototype.isArray()` to determine if `val` is an array and return it as-is or encapsulated in an array accordingly. 6 | 7 | 如果提供的值不是数组,则将其转换为数组。 8 | 9 | 使用 `array.prototype.isarray()` 来确定 `val` 是否是一个数组,如果是数组,按原样返回;如果不是数组,将值封装在数组中返回。 10 | 11 | ```js 12 | const castArray = val => (Array.isArray(val) ? val : [val]); 13 | ``` 14 | 15 | ```js 16 | castArray('foo'); // ['foo'] 17 | castArray([1]); // [1] 18 | ``` 19 | -------------------------------------------------------------------------------- /snippets/filterFalsy.md: -------------------------------------------------------------------------------- 1 | ### filterFalsy 2 | 3 | ------------ 4 | 5 | Filters out the falsy values in an array. 6 | 7 | Use `Array.prototype.filter()` to get an array containing only truthy values. 8 | 9 | ------------ 10 | 11 | 过滤数组中为假值(falsy)的元素。 12 | 13 | 使用 `array .prototype.filter()` 过滤后,数组中只包含为真值(truthy)的元素。 14 | 15 | ```js 16 | const filterFalsy = arr => arr.filter(Boolean); 17 | ``` 18 | 19 | ```js 20 | filterFalsy(['', true, {}, false, 'sample', 1, 0]); // [true, {}, 'sample', 1] 21 | ``` 22 | -------------------------------------------------------------------------------- /snippets/partialRight.md: -------------------------------------------------------------------------------- 1 | ### partialRight 2 | 3 | Creates a function that invokes `fn` with `partials` appended to the arguments it receives. 4 | 5 | Use the spread operator (`...`) to append `partials` to the list of arguments of `fn`. 6 | 7 | ```js 8 | const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials); 9 | ``` 10 | 11 | ```js 12 | const greet = (greeting, name) => greeting + ' ' + name + '!'; 13 | const greetJohn = partialRight(greet, 'John'); 14 | greetJohn('Hello'); // 'Hello John!' 15 | ``` 16 | -------------------------------------------------------------------------------- /snippets/tail.md: -------------------------------------------------------------------------------- 1 | ### tail 2 | 3 | ------------ 4 | 5 | Returns all elements in an array except for the first one. 6 | 7 | Return `Array.prototype.slice(1)` if the array's `length` is more than `1`, otherwise, return the whole array. 8 | 9 | ------------ 10 | 11 | 返回数组中除第一个元素外的所有元素。 12 | 13 | 如果数组的 `length` 大于 `1`, ,则返回 `Array.prototype.slice(1)`,否则返回整个数组。 14 | 15 | ```js 16 | const tail = arr => (arr.length > 1 ? arr.slice(1) : arr); 17 | ``` 18 | 19 | ```js 20 | tail([1, 2, 3]); // [2,3] 21 | tail([1]); // [1] 22 | ``` 23 | -------------------------------------------------------------------------------- /snippets/take.md: -------------------------------------------------------------------------------- 1 | ### take 2 | 3 | ------------ 4 | 5 | Returns an array with n elements removed from the beginning. 6 | 7 | Use `Array.prototype.slice()` to create a slice of the array with `n` elements taken from the beginning. 8 | 9 | ------------ 10 | 11 | 返回从开头开始提取 `n` 个元素的数组。 12 | 13 | 使用 `array.prototype.slice()` 创建数组的一个切片,其中包含从开头开始提取的 `n` 个元素。 14 | 15 | ```js 16 | const take = (arr, n = 1) => arr.slice(0, n); 17 | ``` 18 | 19 | ```js 20 | take([1, 2, 3], 5); // [1, 2, 3] 21 | take([1, 2, 3], 0); // [] 22 | ``` 23 | --------------------------------------------------------------------------------