Ad
Functional Programming
Declarative Programming
Programming Paradigms
Higher-order Functions
Functions
Control Flow
Basic Language Features
Fundamentals
Arrays
Data Types
Iterators
Object-oriented Programming

Es6 comes in handy with the generators and the iterators.
Here is simple example of their usage.
given a number n, below is how to make the array with a iterable number range.
how to use the iterable numbers:


let arr = [...n]


The expression above create an array of from 0 to n.

// logic

  • expand the Number primative and make it a iterable with Symbol.iterator.
  • Attach a generator function that yields each value required.
  • The iterable number can only be used in an array.

You can modify the function to create a desired range. eg an array of values less than n, or an array of values greater than n. Enjoy our challenges.
// logic
Number.prototype[Symbol.iterator] = function * (){
for (let i=0;i<=this;i++) {
 yield i
}

}
// you can use this to create your own range
Arrays
Data Types
Regular Expressions
Declarative Programming
Advanced Language Features
Programming Paradigms
Fundamentals
Strings

A pangram is a sentence using every letter of a given alphabet at least once.
Pangrams have been used to display typefaces, test equipment, and develop skills in handwriting, calligraphy, and keyboarding.

Below is a solution to the following problem
write a function that detects a pangram if a string is passed as an argument.
The function show return true or false
Constraints_

  • input can contain non-word characters
  • solution show be case insensitive
    My solution and logic
  • use an array of alphabets in either Uppercase or Lowercase
  • use the array.prototype.every and array.prototype.map method to check if the string(input) contains each letter once.
  • Don't forget to remove all the non-word Characters from the input. And also remember to convert the input string to case corresponding to your alphabets.
  • When you compare the characters with alphabet array using map. The map function return array true or false
    if the entire map array contains true, the solution is valid. this is where the array.every function comes to play.
let isPangram =str=>'abcdefghijklmnopqrstuvwxyz'
 .split('')// create an array of alphabets
 .map(v=>str.replace(/\W/g,'')// map the array and check if the input contains all the letters in alphabet
 // map function should return [true] for every right character
 .toLowerCase().includes(v))
 .every(v=>v===true)// if the mapped array contains all true values, then the str is a pangram else not.

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam, racecar.

Below its one line solution to this problem
funciton palindrome takes a string and check if its a palindrome or not. return true or false respectively.
/// here's the logic

  • create an array from the string
  • reverse the string and then compare it to the original string.
  • A short One liner for you with es6.
let Palindrome =str=> str.split('').reverse().join('')===str