STYLE SWITCHER

Developer

Array Manipulation Using JavaScript Map Method

Array Manipulation Using JavaScript Map Method

Creating and manipulating Arrays in JavaScript is a task that a JavaScript developer does on a daily basis. In this tutorial, you’ll see how to use JavaScript Map method for Array manipulation to reduce your code and make it more readable.

Let’s have a look at the following example:


let employees = [
    { "first_name": "Hari", "last_name": "Krishnan" },
    { "first_name": "Samuel", "last_name": "Jackson" },
    { "first_name": "Suriel", "last_name": "Johnson" },
    { "first_name": "Roy", "last_name": "Agasthyan" }
];
let full_names = []

let name;

for (let i = 0; i < employees.length; i++) {
    name = employees[i]["first_name"] + ' ' + employees[i]["last_name"]
    full_names.push(name)
}

console.log(full_names)

//  [ 'Hari Krishnan',
//  'Samuel Jackson',
//  'Suriel Johnson',
//  'Roy Agasthyan' ]

As seen in the above code, you have a list of employees in the employees variable. The purpose of the above code is to iterate through the list of employees and concat the first name and the second and create another list with the full name of the employees. Now let’s see how to accomplish the above task using the JavaScript Map method.

Understanding JavaScript Map Method

The map() method creates a new array with the results of calling a provided function on every element in the calling array.

The Map method when applied to an array, applies the provided function to each element of the array and returns a new array. Now let’s see how you can rewrite the above code using the JavaScript Map method and how it reduces the code and improves readablity. Here is how the JavaScript Array can be manipulated to return a new array with the full name of the employees using Map method:

let full = employees.map(function(emp) {
    return emp["first_name"] + ' ' + emp["last_name"]
});

console.log(full)

//  [ 'Hari Krishnan',
//  'Samuel Jackson',
//  'Suriel Johnson',
//  'Roy Agasthyan' ]

As seen in the above code, you have applied the JavaScript map method to the employee's array. Each item inside the array is being applied the callback function where the employee first name and last name are being concatenated to return the full name. The map method returns a new array with the full name of the employees. Now if you compare the above two set of codes, you can see the following plus points:

  • You can get rid of the for loop
  • You don’t need the full_names array to keep the concatenated names.

And if you define the callback function as a separate function it would add up to the readability point of view. Here is how you can do it:

let full = employees.map(get_full_name);

function get_full_name(emp){
    return emp["first_name"] + ' ' + emp["last_name"]
}
More
What’s New In DevTools (Chrome 60)

What’s New In DevTools (Chrome 60)

Note: You can check what version of Chrome you're running at chrome://version. Chrome auto-updates to a new major version about every 6 weeks.

Welcome! New features and major changes coming to DevTools in Chrome 60 include:

  • A new Audits panel, including tests for progressive web apps, performance, accessibility, and best practices.
  • Third-party badges. Find out which third-parties are making network requests, logging to the Console, and executing JavaScript.
  • Continue To Here. A new gesture that can speed up your JavaScript debugging workflow.
  • Predictable debugging for asynchronous JavaScript.
  • Object previews in the Console.
  • Real-time updates in the Coverage tab.
  • A new menu for selecting contexts in the Console.
  • Simpler network throttling options.
  • Async stack traces on by default.

What's New In DevTools (Chrome 60)

Kayce Basques By Kayce Basques Technical Writer at Google Welcome! New features and major changes coming to DevTools in Chrome 60 include: A new Audits panel, including tests for progressive web apps, performance, accessibility, and best practices. Third-party badges. Find out which third-parties are making network requests, logging to the Console, and executing JavaScript. Continue To Here. A new gesture that can speed up your JavaScript debugging workflow. Predictable debugging for asynchronous JavaScript. Object previews in the Console. Real-time updates in the Coverage tab. A new menu for selecting contexts in the Console. Simpler network throttling options. Async stack traces on by default. Note: You can check what version of Chrome you're running at chrome://version. Chrome auto-updates to a new major version about every 6 weeks. Check out the video version of these release notes below or read on to learn more.

New features

New Audits panel, powered by Lighthouse
The Audits panel is now powered by Lighthouse. Lighthouse provides a comprehensive set of tests for measuring the quality of your web pages.

The scores at the top for Progressive Web AppPerformanceAccessibility, and Best Practices are your aggregate scores for each of those categories. The rest of the report is a breakdown of each of the tests that determined your scores. Improve the quality of your web page by fixing the failing tests.

A Lighthouse report
Figure 1. A Lighthouse report

To audit a page:

  • Click the Audits tab.
  • Click Perform an audit.
  • Click Run audit. Lighthouse sets up DevTools to emulate a mobile device, runs a bunch of tests against the page, and then displays the results in the Audits panel.
 

Lighthouse at Google I/O '17

Check out the DevTools talk from Google I/O '17 below to learn more about Lighthouse's integration in DevTools.

Contribute to Lighthouse

Lighthouse is an open-source project. To learn lots more about how it works and how to contribute to it, check out the Lighthouse talk from Google I/O '17 below. Got an idea for a Lighthouse audit? Post it here!

Third-party badges

Use third-party badges to get more insight into the entities that are making network requests on a page, logging to the Console, and executing JavaScript.
Hovering over a third-party badge in the Network panel
Figure 2. Hovering over a third-party badge in the Network panel
Hovering over a third-party badge in the Console
Figure 3. Hovering over a third-party badge in the Console
To enable third-party badges:
  • Open the Command Menu.
  • Run the Show third party badges command.
Use the Group by product option in the Call Tree and Bottom-Up tabs to group performance recording activity by the third-party entities that caused the activities. See Get Started With Analyzing Runtime Performance to learn how to analyze performance with DevTools.
Grouping by product in the Bottom-Up tab
Figure 4. Grouping by product in the Bottom-Up tab
Website
More
YouTube’s redesign is official, and there’s a dark mode

YouTube’s redesign is official, and there’s a dark mode

YouTube has a new look, with the desktop site getting a "Material Design" revamp today. The design has slowly been leaking out in A/B testing, but today the company is making it official.

YouTube says the new design aims for a "simple, consistent, and beautiful" look. Most of YouTube's box-heavy card design has been erased, instead going with a simple white background, the usual grid of thumbnails, and more white space. YouTube makes use of Material Design's trademark shadowing, with a pinned search bar at the top of the screen. It's not a drastic change until you turn on the new "dark mode," which replaces all the white UI with something easier on the eyes. The dark mode switch lives in the new profile menu, which you can access by clicking on your profile picture in the top right.

Material Design was introduced three years ago in Android 5.0 and is meant to be a unifying design style for all of Google. Seeing it finally come to YouTube is nice, but it is still missing from flagship products like Gmail and Google Calendar, which were both last redesigned in 2011.

The design isn't automatically rolling out to everyone yet. Users can opt-in to a "preview" of the design over at youtube.com/new, and it's easy to revert back to the old design if you don't like it. YouTube is soliciting feedback on the new design before a wider rollout; it suggests you leave feedback via the link on the account menu.

YouTube's new interface is built on Google's Polymer framework, a JavaScript library for creating Web components with a focus on creating Material Design-style apps on the Web. With the Polymer base up and running, YouTube says it will have "quicker feature development from here on out." It cites the dark theme as the first of these Polymer-enabled features and ends with saying, "This is only the beginning—you can look forward to more powerful new features coming soon!"

Website
More
Verify your Responsive Website Design with Google Resizer Tool

Verify your Responsive Website Design with Google Resizer Tool

resizer-google-design
Google has come up with a brand new tool called Resizer, which helps Website Designers and Developers alike to test their completed or pre-completed Website Design for its responsiveness or Responsive adaptability. You can check with either different viewing environments such as Desktops, Laptops, Tablets and Smartphones. Or else, you can take up different dimensions which suits your viewing device.
Website
More
YakYak Is A Desktop Client For Hangouts With A Dark Mode, Notification Options, And More

YakYak Is A Desktop Client For Hangouts With A Dark Mode, Notification Options, And More

Dandelion-Flower-bokeh-effect-photography
Windows/Mac/Linux: If you want a desktop version of Google Hangouts, you have plenty of options, including an official option from Google, but the Google route doesn't work super well and requires Chrome to run. YakYak is a desktop client for Hangouts that works like a regular desktop app.
Website
More
Simple way to download youtube videos.

Simple way to download youtube videos.

flat_youtube_wallpaper_by_oscagapotes-d6o637w
if you want to download youtube videos, please follow these steps.
1) open youtube and find the videos you want to download.
2) Replace the URL starting 'https://www.' with 'ss'
   Example if you want to download this video https://www.youtube.com/results?search_query=pattam+pole+songs. in this url to edit and make it as "ssyoutube.com/results?search_query=pattam+pole+songs" and press enter.
3) The page redirect to another page and you will select the format of file to download. and press the download button.
More
Particles.js – jQuery Plugin For Creating Particles

Particles.js – jQuery Plugin For Creating Particles

particles.js is a lightweight JavaScript library for creating particles. This plugins is awesome and suit for landing page.
Website
More
Auto Playlist for HTML5 video

Auto Playlist for HTML5 video

mobile-video-marketing
<figure id="video_player">
 <div id="video_container">
 <video controls poster="http://demosthenes.info/assets/images/vid-glacier.jpg">
 <source src="http://demosthenes.info/assets/videos/glacier.webm" type="video/webm">
 <source src="http://demosthenes.info/assets/videos/glacier.mp4" type="video/mp4">
</video>
</div>
<figcaption>
 <a href="http://demosthenes.info/assets/videos/glacier.mp4" class="currentvid">
 <img src="http://demosthenes.info/assets/images/vid-glacier.jpg" alt="Athabasca Glacier">
 </a>
 <a href="http://demosthenes.info/assets/videos/lake.mp4">
 <img src="http://demosthenes.info/assets/images/vid-lake.jpg" alt="Athabasca Lake">
 </a>
 <a href="http://demosthenes.info/assets/videos/mountain.mp4">
 <img src="http://demosthenes.info/assets/images/vid-mountain.jpg" alt="Mountain">
 </a>
</figcaption>
</figure>

var video_player = document.getElementById("video_player");
video = video_player.getElementsByTagName("video")[0],
video_links = video_player.getElementsByTagName("figcaption")[0],
source = video.getElementsByTagName("source"),
link_list = [],
vidDir = "http://demosthenes.info/assets/videos/",
currentVid = 0,
allLnks = video_links.children,
lnkNum = allLnks.length;
video.removeAttribute("controls");
video.removeAttribute("poster");

(function() {
function playVid(index) {
 video_links.children[index].classList.add("currentvid");
    source[0].src = vidDir + link_list[index] + ".webm";  
	source[1].src = vidDir + link_list[index] + ".mp4";
    currentVid = index;
    video.load();
	video.play();
}

for (var i=0; i<lnkNum; i++) {
var filename = allLnks[i].href;
link_list[i] = filename.match(/([^\/]+)(?=\.\w+$)/)[0];
(function(index){
        allLnks[i].onclick = function(i){
        i.preventDefault();  
		for (var i=0; i<lnkNum; i++) { 		allLnks[i].classList.remove("currentvid"); 		} 		playVid(index);         }         })(i); } video.addEventListener('ended', function () {     allLnks[currentVid].classList.remove("currentvid");     if ((currentVid + 1) >= lnkNum) { nextVid = 0 } else { nextVid = currentVid+1 }
    playVid(nextVid);
})

video.addEventListener('mouseenter', function() {
    video.setAttribute("controls","true");
})

video.addEventListener('mouseleave', function() {
    video.removeAttribute("controls");
})

var indexOf = function(needle) {
    if(typeof Array.prototype.indexOf === 'function') {
        indexOf = Array.prototype.indexOf;
    } else {
        indexOf = function(needle) {
            var i = -1, index = -1;
			for(i = 0; i < this.length; i++) {
                if(this[i] === needle) {
                    index = i;
                    break;
                }}
            return index;
        };}
    return indexOf.call(this, needle);
};
 	var focusedLink = document.activeElement;
 	index = indexOf.call(allLnks, focusedLink);
 	
document.addEventListener('keydown', function(e) {
if (index) {
	var focusedElement = document.activeElement;
    if (e.keyCode == 40 || e.keyCode == 39) { // down or right cursor
    var nextNode = focusedElement.nextElementSibling;
    if (nextNode) { nextNode.focus(); } else { video_links.firstElementChild.focus(); }
    }
   if (e.keyCode == 38 || e.keyCode == 37) { // up or left cursor
    var previousNode = focusedElement.previousElementSibling;
    if (previousNode) { previousNode.focus(); } else { video_links.lastElementChild.focus(); }
    }
 }
});

})();  

More
Stackfield

Stackfield

www.stackfield.com
Highly secured communication for business teams
Stackfield is the secured place for all your team communication including real-time messaging, file transfer and task management. https://www.stackfield.com/
More
Vivaldi

Vivaldi

Vivaldi will adapt as you browse the web. A clean and modern interface to complement the content you are browsing. It’s also highly customizable – don’t like the tabs on top? Simply put them where you want, bottom, left or right.
https://vivaldi.com/#Home
More