Skip to content

Instantly share code, notes, and snippets.

View swaraj89's full-sized avatar
🎯
Focusing

Swaraj Panigrahi swaraj89

🎯
Focusing
View GitHub Profile
@swaraj89
swaraj89 / print-series.js
Created August 22, 2017 13:10
Write a program to print a sequence from 0,1,2,3,....n,n-1,n-2.....0 in JS
function getSeries(limit){
var series = "";
var counter = 1;
for(var i=1; i>0; i+=counter){
if(i==limit){
counter= -1;
}
series += (i + " ");
};
@swaraj89
swaraj89 / getIndicesOf.js
Created May 12, 2017 05:09
Solutions to BLITZ problem statements
/**
*Simpler solution using for loop; without using any array.indexOf()
*/
Array.prototype.getIndicesOf = function(item){
var indices = [];
for(var i=0; i < this.length; i++){
if(this[i] === item){
indices.push(i);
@swaraj89
swaraj89 / getIndicesOfFor.js
Last active April 15, 2017 15:24
JS array polyfill to get all occurrence of an item in a array. (while loop and for Loop)
/**
*Simpler solution using for loop; without using any array.indexOf()
*/
Array.prototype.getIndicesOf = function(item){
var indices = [];
for(var i=0; i < this.length; i++){
if(this[i] === item){
indices.push(i);