Skip to content

Instantly share code, notes, and snippets.

@swaraj89
swaraj89 / print-series.js
Created Aug 22, 2017
Write a program to print a sequence from 0,1,2,3,....n,n-1,n-2.....0 in JS
View print-series.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
Solutions to BLITZ problem statements
View getIndicesOf.js
/**
*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 Apr 15, 2017
JS array polyfill to get all occurrence of an item in a array. (while loop and for Loop)
View getIndicesOfFor.js
/**
*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);