Showing posts sorted by relevance for query javascript. Sort by date Show all posts
Showing posts sorted by relevance for query javascript. Sort by date Show all posts

Saturday, May 25, 2019

Javascript Basics


Javascript Basics

JavaScript presentation

Why Study JavaScript?

JavaScript is one of the 3 languages all web developers must learn:

   1. HTML to define the content of web pages
   2. CSS to specify the layout of web pages
   3. JavaScript to program the behavior of web pages

Web pages are not the only place where JavaScript is used. Many desktop and server programs use JavaScript. Node.js is the best known. Some databases, like MongoDB and CouchDB, also use JavaScript as their programming language.



Sunday, August 13, 2017

jQuery Presentation


jQuery Basics



What is Jquery?

Fast and ConsiseJavascriptLibrary created by John Resigin 2006

jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of May 2019, jQuery is used by 73% of the 10 million most popular websites. Web analysis indicates that it is the most widely deployed JavaScript library by a large margin, having 3 to 4 times more usage than any other JavaScript library


Friday, August 23, 2019

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript 




<!DOCTYPE html>
<html>
<head>

<script>
function startTime() {
  var today = new Date();
  var h = today.getHours();
  var m = today.getMinutes();
  var s = today.getSeconds();
  m = checkTime(m);
  s = checkTime(s);
  document.getElementById('txt').innerHTML =
  h + ":" + m + ":" + s;
  var t = setTimeout(startTime, 500);
}
function checkTime(i) {
  if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
  return i;
}
</script>

<style>
#txt{
color:white;
background-color:rgb(60, 60, 60);
padding:20px;
text-align: center;
margin: 60px;

}
</style>
</head>

<body onload="startTime()">

<div id="txt">  </div>

</body>
</html>



 



Saturday, November 4, 2023

Sorting on the basis of multiple fields

 function sortObjects(arr) {

arr.sort(function(a, b) { if (a.adviserid < b.adviserid) { return -1; } else if (a.adviserid > b.adviserid) { return 1; } else { if (a.cutomer_id < b.cutomer_id) { return -1; } else if (a.cutomer_id > b.cutomer_id) { return 1; } else { if (a.account_id < b.account_id) { return -1; } else if (a.account_id > b.account_id) { return 1; } else { if (a.product_type === b.product_type) { if (a.account_id > b.account_id) { return -1; } else if (a.account_id < b.account_id) { return 1; } } return 0; } } } }); // Group the array by adviserid var groupedArr = []; var currentAdviserId = null; for (var i = 0; i < arr.length; i++) { var obj = arr[i]; if (obj.adviserid !== currentAdviserId) { currentAdviserId = obj.adviserid; groupedArr.push([]); } groupedArr[groupedArr.length - 1].push(obj); } return groupedArr; }

Here's how you would use this function:

// Example array of objects var arr = [ { adviserid: 1, cutomer_id: "abc", account_id: 10, product_type: "A" }, { adviserid: 1, cutomer_id: "abc", account_id: 20, product_type: "A" }, { adviserid: 1, cutomer_id: "def", account_id: 30, product_type: "B" }, { adviserid: 2, cutomer_id: "ghi", account_id: 40, product_type: "A" } ]; // Call the function to sort the array var sortedArr = sortObjects(arr); // Print the sorted array console.log(sortedArr);

In this example, the arr array contains four objects with adviserid, cutomer_id, account_id, and product_type properties. The sortObjects function sorts the array based on the three fields you specified (in ascending order), and then groups the sorted array by adviserid. The sorted and grouped array is then printed to the console.

In the sorting logic, the function first sorts by adviserid, then by cutomer_id, and then by account_id. If two objects have the same product_type, they are sorted by account_id in descending order. If two objects have the same adviserid, they are grouped together in the output array.




Sure, here's an example JavaScript function that sorts an array of objects based on the three fields you specified:

function sortObjects(arr) { arr.sort(function(a, b) { if (a.adviserId < b.adviserId) { return -1; } else if (a.adviserId > b.adviserId) { return 1; } else { if (a.priority < b.priority) { return -1; } else if (a.priority > b.priority) { return 1; } else { if (a.accountId < b.accountId) { return 1; } else if (a.accountId > b.accountId) { return -1; } else { return 0; } } } }); return arr; } // Example array of objects var arr = [ { adviserId: 2, priority: 1, accountId: 10 }, { adviserId: 1, priority: 2, accountId: 20 }, { adviserId: 1, priority: 2, accountId: 30 }, { adviserId: 2, priority: 1, accountId: 40 } ]; // Print the input array console.log("Input: ", arr); // Call the function to sort the array var sortedArr = sortObjects(arr); // Print the sorted array console.log("Output: ", sortedArr);

In this example, the arr array contains four objects with adviserId, priority, and accountId properties. The sortObjects function sorts the array based on the three fields you specified, with priority being sorted in ascending order. If two objects have the same priority, they are sorted by accountId in descending order. The input and output arrays are then printed to the console.

The output of this function will be:

Input: [ { adviserId: 2, priority: 1, accountId: 10 }, { adviserId: 1, priority: 2, accountId: 20 }, { adviserId: 1, priority: 2, accountId: 30 }, { adviserId: 2, priority: 1, accountId: 40 } ] Output: [ { adviserId: 1, priority: 2, accountId: 30 }, { adviserId: 1, priority: 2, accountId: 20 }, { adviserId: 2, priority: 1, accountId: 40 }, { adviserId: 2, priority: 1, accountId: 10 } ]

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > <...

Followers

Search This Blog

Popular Posts