Exercise: String Slicing
Test your knowledge of the slice function.
We'll cover the following...
Sort the rows given below based on their titles. Make sure you exclude the header row.
Hint: the
slice
method works in the same way on arrays as on strings.
Solution
First, we get rid of the first row:
Press + to interact
const data = `Title,Author,Publication Date,PublisherES6 in Practice,Zsolt Nagy,2017,Self-publishedThe Developer's Edge,Zsolt Nagy,2016,Self-publishedRegex Quick Syntax Reference,Zsolt Nagy,2018,ApressThe Charismatic Coder,Zsolt Nagy,2018,Self-publishedDeep Dive into Functional JavaScript,Zsolt Nagy,2017,PacktPubImplementing and Testing Applications using Functional JavaScript,Zsolt Nagy,2017,PacktPubMastering Functional JavaScript Libraries,Zsolt Nagy,2017,PacktPubBeginning Modern JavaScript Development with Microservices WebRTC and React,Zsolt Nagy,2017,PacktPubBeginning ASP.NET,Zsolt Nagy,2017,PacktPubBecome the CSS Hero of Your Office with CSS Architecture,Zsolt Nagy,2017,SitePointSetting Up and Kick Starting TypeScript,Zsolt Nagy,2017,SitePoint`;const result = data.trim().split('\n').map( row => row.split(',') );const dataRows = result.slice( 1 );console.log(dataRows)
We have to sort the data rows using the array sort ...