Javascript Snippets
Javascript Snippets
Secret Code Snippets used by Powerful Developers to create Innovative Apps
About the Book
This book is for anyone with a basic working understanding of JS.
It covers 9 chapters with innovative and interesting ways of solving common situations when working with Arrays, Objects, NodeJS, Functions, Browser and more.
The idea is for you to also use some of the snippets as plug and play functions in your projects.
Why learn in this way ?
Javascript is one of the most versatile and powerful programming languages, learning the basics and using libraries like Jquery is really easy, however most of the time the solutions to the problems we face might be coded in a simpler and more efficient way.
This book serves as a reference guide providing code snippets written in an efficient way, by studying each of them, and even customizing some of the snippets to better suit your project you will get in the habit of writing code like a god.
If you really want to develop a mindset which allows you to code in a precise and fast way, then there’s no escape. You must understand the idea behind each snippet and implement it on a project, by having the experience and solving all the challenges you face you will become a successful developer.
Check out other books from the author:
Front End Developer Interview Questions
Bundles that include this book
Table of Contents
-
Introduction
- The Unique Advantage this Book will allow you to unleash
- Who is this book for ?
- What is covered in this book ?
-
Chapter 1: Array related snippets
- all
- allEqual
- any
- compact
- difference
- drop
- dropRight
- everyNth
- filterNonUnique
- findLast
- head
- includesAll
- includesAny
- initial
- last
- maxN
- minN
- none
- nthElement
- offset
- reject
- sample
- similarity
- tail
- take
- union
- uniqueElements
- without
- arrayToCSV
- bifurcate
- bifurcateBy
- chunk
- chunkIntoN
- countBy
- countOccurrences
- deepFlatten
- differenceBy
- differenceWith
- dropRightWhile
- dropWhile
- filterNonUniqueBy
- findLastIndex
- flatten
- forEachRight
- frequencies
- groupBy
- haveSameContents
- indexOfAll
- initialize2DArray
- initializeArrayWithRange
- initializeArrayWithRangeRight
- initializeArrayWithValues
- initializeNDArray
- intersection
- intersectionBy
- intersectionWith
- isContainedIn
- isSorted
- join
- longestItem
- mapObject
- mostFrequent
- normalizeLineEndings
- partition
- pull
- reduceSuccessive
- reduceWhich
- reducedFilter
- remove
- sampleSize
- shank
- shuffle
- sortedIndex
- sortedIndexBy
- sortedLastIndex
- sortedLastIndexBy
- stableSort
- symmetricDifference
- symmetricDifferenceBy
- symmetricDifferenceWith
- takeRight
- takeRightWhile
- takeWhile
- toHash
- unionBy
- unionWith
- uniqueElementsBy
- uniqueElementsByRight
- uniqueSymmetricDifference
- unzip
- xProd
- zip
- zipObject
- JSONtoCSV
- permutations
- pullAtIndex
- pullAtValue
- pullBy
- unzipWith
- weightedSample
- zipWith
-
Chapter 2: Browser related snippets
- createElement
- currentURL
- getImages
- getBaseURL
- getStyle
- hasClass
- hide
- insertAfter
- insertBefore
- isBrowserTabFocused
- nodeListToArray
- redirect
- setStyle
- show
- toggleClass
- UUIDGeneratorBrowser
- arrayToHtmlList
- bottomVisible
- detectDeviceType
- elementContains
- formToObject
- getScrollPosition
- getURLParameters
- httpDelete
- httpGet
- httpPost
- httpPut
- httpsRedirect
- isBrowser
- off
- on
- parseCookie
- prefersDarkColorScheme
- prefersLightColorScheme
- prefix
- recordAnimationFrames
- scrollToTop
- serializeCookie
- serializeForm
- smoothScroll
- supportsTouchEvents
-
Chapter 3: Date related snippets
- dayOfYear
- getMeridiemSuffixOfInteger
- isAfterDate
- isBeforeDate
- isLeapYear
- isSameDate
- isWeekday
- isWeekend
- maxDate
- minDate
- getColonTimeFromDate
- formatDuration
- getDaysDiffBetweenDates
- tomorrow
- yesterday
-
Chapter 4: Function related snippets
- checkProp
- functionName
- negate
- nthArg
- timeTaken
- unary
- ary
- attempt
- bind
- bindKey
- call
- chainAsync
- collectInto
- compose
- composeRight
- converge
- curry
- debounce
- defer
- delay
- flip
- hz
- mostPerformant
- once
- over
- overArgs
- partial
- partialRight
- pipeAsyncFunctions
- pipeFunctions
- promisify
- rearg
- runPromisesInSeries
- sleep
- spreadOver
- times
- uncurry
- unfold
- when
- throttle
-
Chapter 5: Math related snippets
- accumulate
- approximatelyEqual
- average
- celsiusToFahrenheit
- clampNumber
- digitize
- degreesToRads
- distance
- factorial
- fahrenheitToCelsius
- fibonacci
- gcd
- inRange
- isDivisible
- isEven
- isNegativeZero
- isOdd
- isPowerOfTwo
- isPrime
- lcm
- mapNumRange
- maxBy
- midpoint
- minBy
- powerset
- radsToDegrees
- randomHexColorCode
- randomIntegerInRange
- randomNumberInRange
- sum
- toDecimalMark
- toSafeInteger
- vectorAngle
- vectorDistance
- averageBy
- binomialCoefficient
- geometricProgression
- hammingDistance
- median
- percentile
- primes
- randomIntArrayInRange
- round
- sdbm
- standardDeviation
- sumBy
- sumPower
- toCurrency
- toOrdinalSuffix
- validateNumber
- luhnCheck
-
Chapter 6: Node related snippets
- atob
- btoa
- createDirIfNotExists
- untildify
- readFileLines
- JSONToFile
- colorize
- UUIDGeneratorNode
- hasFlags
- hashNode
- isDuplexStream
- isReadableStream
- isStream
- isTravisCI
- isWritableStream
- atob
- btoa
- createDirIfNotExists
- readFileLines
- untildify
- JSONToFile
- UUIDGeneratorNode
- colorize
- hasFlags
- hashNode
- isDuplexStream
- isReadableStream
- isStream
- isTravisCI
- isWritableStream
-
Chapter 7: Object related snippets
- objectFromPairs
- objectToEntries
- objectToPairs
- shallowClone
- bindAll
- deepClone
- deepFreeze
- deepGet
- defaults
- dig
- findKey
- findLastKey
- flattenObject
- forOwn
- forOwnRight
- functions
- get
- hasKey
- invertKeyValues
- lowercaseKeys
- mapKeys
- mapValues
- matches
- matchesWith
- merge
- nest
- objectToQueryString
- omit
- omitBy
- orderBy
- pick
- pickBy
- renameKeys
- size
- toPairs
- transform
- truthCheckCollection
- deepMapKeys
- equals
- unflattenObject
-
Chapter 8: Strings related snippets
- byteSize
- compactWhitespace
- containsWhitespace
- indentString
- isLowerCase
- isUpperCase
- mapString
- pad
- reverseString
- sortCharactersInString
- splitLines
- stripHTMLTags
- truncateString
- unescapeHTML
- CSVToArray
- RGBToHex
- capitalize
- capitalizeEveryWord
- decapitalize
- escapeHTML
- escapeRegExp
- extendHex
- fromCamelCase
- isAbsoluteURL
- isAnagram
- mask
- palindrome
- pluralize
- removeNonASCII
- toCamelCase
- toKebabCase
- toSnakeCase
- toTitleCase
- words
- yesNo
- CSVToJSON
- URLJoin
- hexToRGB
- prettyBytes
- stringPermutations
-
Chapter 9: Type related snippets
- castArray
- coalesce
- getType
- is
- isBoolean
- isEmpty
- isFunction
- isNil
- isNull
- isNumber
- isObject
- isObjectLike
- isString
- isSymbol
- isUndefined
- cloneRegExp
- coalesceFactory
- isArrayLike
- isPlainObject
- isPrimitive
- isPromiseLike
- isValidJSON
-
Bonus Projects
- Ecommerce Customer Satisfaction Project
- The data to work with
- The requirements
- Let’s build our script
- Keep Exploring and Coding
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them