# ➤ Misc

`Write a JavaScript program to find the most frequent item of an array. Search should be case insensitive.input: [1, 'T', 'a', 'T', 2, 3, 'T', 3, 't', 2, 't', 9, 3];output: t = 5Attach a function to array in js?let tempArray = [6, 2, 3, 4, 5];let averageValues = tempArray.average();console.log(averageValues); // should return average of tempArray`

# ◉ sum of no.s using Recursion

`var array_sum = function(arr) {  if (arr.length === 1) {    return arr[0];  }  return arr.pop() + array_sum(arr);  };console.log(array_sum([1,2,3,4,5,6]));# 21`
`// functional approachconst log = message => console.log(message);`
`const increaseByOne = num => num + 1;const num = 1const newNum = increaseByOne(num) // => 2console.log(num) // => 1`
`const sum = (a,b) => a + bconst average = (fn, ...nums) => nums.reduce(fn) / nums.length;const numsAvg = average(sum, 1, 2, 3) // => 2`

# ◉ sum of (numbers) when you don’t know how many numbers are there…rest operator.

`const sum = (...args)=>{ return args.reduce((a, b) => a+b);}console.log(sum(2,3,4,6));# 15`

# (…) Rest parameter syntax

`function numbers(x,y, ...z){    console.log(x,y,z);}numbers(1,2,3,4,5,6);# Output: 12[3,4,5,6]`

`function getSum(x, y, z){   console.log(x+y+z);}let arr = [10,20,30];getSum(...sumArray);`

# ◉ “this”

`var foo = { name: "anil", age: 30};function getDetails() { return (this.name + " is + this.age + " yrs old.");}foo.logMyDetails = getDetails;console.log(foo.logMyDetails());//anil is 30 yrs old.▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬function Employee(name) { this.name = name; this.getName = function () {  return this.name; }}var e1 = new Employee(“anil");e1.getName(); #anil ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬function Employee(name) { this.name = name;}Employee.getName = function () { return this.name;}var e2 = new Employee("kumar");e2.getName();        #TypeErrorvar e3 = e2.getName;console.log(e3());   #TypeErrorvar e4 = e2.getName.bind(e2);console.log(e3());   #TypeError ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬var x = "outermost";var foo = {      x: "inner",      baz: {           x: "innermost",           bar: function () {              return this.x;           }      }}var go = foo.baz.bar;       # "this" refers to global objectconsole.log(go());console.log(foo.baz.bar())# outermost# innermost`

# Getting key with the highest value from object

`var obj = {a: 1, b: 2, undefined: 1};Object.keys(obj).reduce(function(a, b){ return obj[a] > obj[b] ? a : b });`

# Q. find the most frequent item in an array

`Write a JavaScript program to find the most frequent item of an array. Search should be case insensitive.input: [1, 'T', 'a', 'T', 2, 3, 'T', 3, 't', 2, 't', 9, 3];output: t = 5`

# Add a method to Array object in Javascript?

`var arr = [2,3,4,5];arr.getSum = function() {    var sum= 0;   for(var i=0; i< arr.length; i++){      sum = sum + arr[i];   };   console.log(sum);}arr.getSum();`

# Chaining ( as in jQuery)

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.

## More from Anil Kumar

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.