Skip to content

Instantly share code, notes, and snippets.

View kotAPI's full-sized avatar
🎯
Focusing

Pranay Kothapalli kotAPI

🎯
Focusing
View GitHub Profile
function getNthSeriesInAP(a,d,n){
/**
* a = first number in the AP
* n = Nth element of the series
* d = difference of the AP
*/
return a+(n-1)*d
}
console.log((getNthSeriesInAP(0,2,101)))
/// => 200
function shuffle(inputArr){
for(var i=0;i<inputArr.length;i++){
// Javascript way to implement a random number between a range
// The internals of how the random number is generated is not important
// in this scope, just know that the following line returns a number in a range
// random(min,max)
var randomIndex = Math.floor(Math.random() * (inputArr.length - i) + i)
// Swapping the numbers
var temp = inputArr[i]
//
function linearSearch(arr,number){
for(var i=0;i<arr.length;i++){
if(arr[i]===number){
// The required number is found, return it's index
return i;
}
}
/// Looping is complete, the number wasn't encountered in the supplied array,
// Return NOT_FOUND
//
function binarySearch(arr,number){
// key at left side of the array
var min = 0;
var max = arr.length-1;
// Assigning a default value isn't necessary, let's assign it undefined
var mid = undefined