Skip to content

Instantly share code, notes, and snippets.

@niteshpsit1
niteshpsit1 / gist:c90b3336ee639c89ae13b98825c9d9ca
Created December 1, 2016 10:26
Sorting an array order by frequency of occurence in javascript
/**
* Sorting an array order by frequency of occurence in javascript
* @param {array} array An array to sort
* @returns {array} array of item order by frequency
**/
function sortByFrequency(array) {
var frequency = {};
var sortAble = [];
var newArr = [];
var fs = require('fs')
var path = require('path')
/**
* function To generate the descption for test
* @param { String } filename name of api for which we need to generate test cases
* @returns { String } template for test cases
**/
function getTestTemplate(endpoint, httpMethod = 'GET') {
endpoint = JSON.stringify(endpoint)
return `var chai = require('chai');
var chokidar = require('chokidar');
var fs = require('fs')
var path = require('path')
var testFileExtension = 'spec.js'
var ignorefile = [/[\/\\]\./, 'package.json', 'node_modules', 'watcher.js'];
/**
* @getTemplate A function to get Tempate content for new test file
* @filename It just take on argument that is file
* @returns : string
**/
@niteshpsit1
niteshpsit1 / sortings
Last active March 25, 2017 09:44
sorting programs
let arrayToBeSort = [12,45,75,35,55,54,2,21]
// ## Bubble Sort
/**
*
* Bubble sort is a simple sorting algorithm.
* This sorting algorithm is comparison-based algorithm
* in which each pair of adjacent elements is compared
* and the elements are swapped if they are not in order.
* This algorithm is not suitable for large data sets as
/**
* Linear search is a very simple search algorithm.
* In this type of search, a sequential search is made over all items one by one.
* Every item is checked and if a match is found then that particular item is returned,
* otherwise the search continues till the end of the data collection.
* @param {*} arr : An array in which you want to search the value
* @param {*} valueToSearch : value to be search in array
*/
function linearSearch(arr , valueToSearch){