Skip to content

Instantly share code, notes, and snippets.

@drGrove
Created May 16, 2014 20:30
Show Gist options
  • Select an option

  • Save drGrove/f75f289c4adcf4da78cb to your computer and use it in GitHub Desktop.

Select an option

Save drGrove/f75f289c4adcf4da78cb to your computer and use it in GitHub Desktop.
Rightmost Char
'use strict'
var fs = require('fs');
fs
.readFileSync(process.argv[2])
.toString()
.split('\n')
.forEach(function(line){
if(line != ""){
line = line.split(',')
var string = line[0];
var search = line[1] || '';
var positions = [];
if(search != ''){
for(var i = 0; i < string.length; i++){
var charac = string[i]
if(charac == search)
positions.push(i)
}
}
console.log(positions[positions.length - 1] || -1)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment