Following is the code for adding properties and methods to an existing object in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; color: blueviolet; } Add properties and methods to an existing object in JavaScript CLICK HERE Click on the above button to add property and methods to student object and display them let resEle = document.querySelector(".result"); let BtnEle = ... Read More
Currying − In currying a function takes another function and some arguments. The function then returns one function with one parameter only. It returns the function with one argument which can be chained together.Partial application − In partial application some of the arguments can be bind to some values to produce a function with less arguments.Following is the code for currying vs partial application in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; ... Read More
Following is the code for drawing an image in canvas using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } Drawing an image in canvas CLICK HERE Click on the above button to draw the image in canvas let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); BtnEle.addEventListener("click", () => { var c = document.querySelector(".canvas1"); var ctx = c.getContext("2d"); var img = document.querySelector(".flower"); ctx.drawImage(img, 10, 10); }); OutputOn clicking the ‘CLICK HERE’ button −
We have a list containing only numbers. We plan to get the average of a set of sequential numbers from the list which keeps rolling from the first number to next number and then to next number and so on.ExampleThe below example simplifies the requirement of finding the average of each 4-length consecutive elements of the list.Given list: [10, 12, 14, 16, 18, 20, 22, 24, 26] Average of every segment of 4 consecutive numbers: [13.0, 15.0, 17.0, 19.0, 21.0, 23.0]With sum and rangeWe use the list comprehension approach to take the sum of the consecutive numbers by ... Read More
JavaScript treats functions as objects and allow us to pass functions as parameter to another function and even return functions from other functions. In JavaScript the functions are first class functions meaning we can store them in variable, objects and array. The higher order functions can take function, return them or do both.Following is the code to implement first class functions in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: ... Read More
JavaScript has the following values evaluate to false when evaluated as Boolean type − false0empty string: "" , '' , or ``nullundefinedNaN — not a number valueFollowing is the code for identifying falsy values in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result{ font-size: 20px; font-weight: 500; color: blueviolet; } Identifying Falsy values in JavaScript. CLICK HERE Click on the above button to identify some of the ... Read More
TKinter is a Python module which is used for GUI programming in Python. We create a Canvas and place our UI components with many properties and behaviors in it. In this article, we will see e how to use the ask essay file function to save files created through Python programs into the local drives.We first create a canvas on which we again place a button using the TTK dot button function. Then declare another function that will use the ask fine to define the file type and save the file into location in the local drive.Examplefrom tkinter import * ... Read More
Following is the code for implementing linear search in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result,.sample { font-size: 20px; font-weight: 500; color: blueviolet; } .sample{ color:red; } Implementing linear search [1,19,5,11,22,55] CLICK HERE Click on the above button to search for 22 in the above array let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let arr = [1,19,5,11,22,55]; BtnEle.addEventListener("click", () => { for(let i=0;i
In ES6, if the object key name and variables passed as properties value have same name then we can simply omit the value name and only specify the key name.Following is the code for property shorthands in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; color: blueviolet; } ES6 Property Shorthands in JavaScript CLICK HERE Click on the above ... Read More
Python can help us use excel files directly from the python environment. We can refer to the each cell or a range of cells in excel and apply arithmetic operators on those cells. The results of those operations can also be stored at some cells whose location can be specified by the python program.In the below examples we are performing various arithmetic operations using inbuilt functions of excel. Like sum or average of numbers inside cells. The results are also stored at specific locations. We use the openpyxl module which opens a workbook and marks it active. Then we store ... Read More