To remove and add new HTML tags, use the concept of hide() and show().Let’s say the following are our buttons −Click Me To hide above content Click Me To show above content To remove and add tags on button clicks, use hie() and show() −$(document).ready(function(){ $("#hide").click(function(){ $("h1").hide(); }); $("#show").click(function(){ $("h1").show(); }); });Example Live Demo Document Test JavaScript Click Me To hide above content Click Me To show above content $(document).ready(function(){ $("#hide").click(function(){ ... Read More
Let’s say the following are our values −let subjectNames = ['JavaScript', 'Angular', 'AngularJS', 'Java'];To count the non-empty and non-null values, use the forEach(). The syntax is as follows −yourArrayName.forEach(anyVariableName =>{ yourStatement1 . . . N } } )Now, use the if statement and check −var count=0 subjectNames.forEach(subject =>{ if(subject!=' ' || subject!=null){ count+=1; } } )Examplelet subjectNames = ['JavaScript', 'Angular', 'AngularJS', 'Java']; var count=0 subjectNames.forEach(subject =>{ if(subject!=' ' || subject!=null){ count+=1; } } ) console.log("Number of subject=="+count);To ... Read More
Let’s say, we have the following objects in JavaScript −ObjectValue =[ { "id": "101", "details": { Name:"John", subjectName:"JavaScript" }}, { "id": "102", "details": { Name:"David", subjectName:"MongoDB" }}, { "id": "103" } ]To remove an object using filter(), the code is as follows −ExampleObjectValue =[ { "id": "101", "details": { Name:"John", subjectName:"JavaScript" }}, { "id": "102", "details": { Name:"David", subjectName:"MongoDB" }}, { "id": "103" } ] output=ObjectValue.filter(obj=>obj.details) console.log(output)To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo46.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo46.js ... Read More
Suppose we have a list of numbers called nums, we have to find the number of times that the list changes from positive-to-negative or negative-to-positive slope.So, if the input is like [2, 4, 10, 18, 6, 11, 13], then the output will be 2, as it changes the direction at 10 (positive-to-negative), and then at 6 (negative-to-positive).To solve this, we will follow these steps −To solve this, we will follow these steps −for i in range 1 to size of nums - 1, doif nums[i-1] < nums[i] > nums[i+1] or nums[i-1] > nums[i] < nums[i+1], thencount := count + 1return ... Read More
Suppose we have a list of numbers called cells; this list is representing sizes of different cells. Now, in each iteration, the two largest cells a and b interact according to these rules: So, If a = b, they both die. Otherwise, the two cells merge and their size becomes floor of ((a + b) / 3). We have to find the size of the last cell or return -1 if there's no cell is remaining.So, if the input is like [20, 40, 40, 30], then the output will be 16, in first iteration, 40 and 40 will die, then ... Read More
Suppose we have a list of words, we have to concatenate them in camel case format.So, if the input is like ["Hello", "World", "Python", "Programming"], then the output will be "helloWorldPythonProgramming"To solve this, we will follow these steps −s := blank stringfor each word in words −make first letter word uppercase and rest lowercaseconcatenate word with sret := s by converting first letter of s as lowercasereturn retLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, words): s = "".join(word[0].upper() + word[1:].lower() for word in words) return ... Read More
Suppose we have a lowercase alphabet string s, and an offset number say k. We have to replace every letter in s with a letter k positions further along the alphabet. We have to keep in mind that when the letter overflows past a or z, it gets wrapped around the other side.So, if the input is like "hello", k = 3, then the output will be "khoor"To solve this, we will follow these steps −Define a function shift(). This will take ci := ASCII of (c) - ASCII of ('a')i := i + ki := i mod 26return character ... Read More
Suppose we have a list of prices of cars for sale, and we also have a budget k, we have to find the maximum number of cars we can buy.So, if the input is like [80, 20, 10, 30, 80], k = 85, then the output will be 3 as we can buy three cars with prices 20, 10, 40To solve this, we will follow these steps −count := 0sort the list pricesfor i in range 0 to size of prices, doif prices[i]
Suppose we have a binary list called fighters and another list of binary lists called bosses. In fighters list the 1 is representing a fighter. Similarly, in bosses list 1 representing a boss. That fighters can beat a boss’s row if it contains more fighters than bosses. We have to return a new bosses matrix with defeated boss rows removed.So, if the input is like fighters = [0,1,1]011000001011111then the output will be011111To solve this, we will follow these steps −fighter_cnt := sum of all elements of fightersresult := a new listfor each row in bosses, doif fighter_cnt
Suppose we have a list of strings called book, if we page an index (0-indexed) into the book, and page_size, we have to find the list of words on that page. If the page is out of index then simply return an empty list.So, if the input is like book = ["hello", "world", "programming", "language", "python", "c++", "java"] page = 1 page_size = 3, then the output will be ['language', 'python', 'c++']To solve this, we will follow these steps −l:= page*page_sizereturn elements of book from index l to l+page_size - 1Let us see the following implementation to get better understanding ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP