Skip to content

Instantly share code, notes, and snippets.

👩‍💻
...

Happiness Nwosu NEbere

👩‍💻
...
Block or report user

Report or block NEbere

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@NEbere
NEbere / findNonRepeatingChars.js
Created May 15, 2019
Given a string, find the non-repeating characters and return in form of an array
View findNonRepeatingChars.js
function findNonRepeatingChars(string) {
const stringArray = string.split('')
const nonrecurring = []
const resultObj = {}
for(let char of stringArray) {
if(!resultObj[char]) {
resultObj[char] = 1;
} else {
resultObj[char] += 1;
@NEbere
NEbere / factorise.js
Created Feb 11, 2016
Factorisation of a digit in javascript
View factorise.js
function factorialize(num) {
//check if num == 0
if (num === 0) {
return 1;
}
//else calculate factorial
return num * factorialize(num - 1);
}
//calling the function. this will return 120
factorialize(5);
View binarygap.php
// Codility Bbinary Gap Test
function solution($N) {
// write your code in PHP5.5
$binaryNumber = decbin($N); // binary conversion of number
$trimmed = trim($binaryNumber, 0); // trim to remove trailing zeros
$binaryGap = explode("1",$trimmed); // explode
$binaryCount = array_map('strlen', $binaryGap);
return max($binaryCount); // returns the longest binary gap
View findDiagonalDifference.py
# Python3 solution to https://www.hackerrank.com/challenges/diagonal-difference/problem
# test data
first_array = [11, 2, 4]
second_array = [4, 5, 6]
third_array = [10, 8, -12]
sumArray = []
sumArray.append(first_array)
sumArray.append(second_array)
sumArray.append(third_array)
View frog_jump.py
# Python2 solution for codility frog jump question
# https://codility.com/programmers/lessons/3-time_complexity/frog_jmp/
import math
def solution(X, Y, D):
# write your code in Python 2.7
source_and_destination_difference = Y - X
fixed_distance_jump = D
@NEbere
NEbere / rotate_array.py
Last active Nov 24, 2016
Given an array of integers and a number, , perform left rotations on the array.
View rotate_array.py
# A left rotation operation on an array of size shifts each of the array's elements 1 unit to the left.
# For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2]
#Given an array of n integers and a number,d , perform d left rotations on the array.
#Then print the updated array as a single line of space-separated integers.
def rotate(array, position):
#print
print (array[position:] + array[:position])
#or return
@NEbere
NEbere / ending.js
Created Feb 11, 2016
Check if a string (first argument) ends with the given target string (second argument).
View ending.js
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var tagLen = target.length;
var str_len = ((-str.length) + tagLen );
var sub_str = str.substr(-tagLen, tagLen);
if(target == sub_str){
return true;
@NEbere
NEbere / largest_number_inArray.js
Created Feb 11, 2016
Returns the largest number in each sub array
View largest_number_inArray.js
function largestOfFour(arr) {
var results = [];
for (var n in arr) {
var largestNumber = 0;
for (var sb in arr[n]) {
if (arr[n][sb] > largestNumber) {
largestNumber = arr[n][sb];
}
}
results[n] = largestNumber;
@NEbere
NEbere / title_case.js
Created Feb 11, 2016
Return the provided string with the first letter of each word capitalized.
View title_case.js
function titleCase(str) {
var strArray = str.toLowerCase().split(' ');
for (var i = 0; i < strArray.length; i++) {
strArray[i] = strArray[i][0].toUpperCase() + strArray[i].slice(1);
}
return strArray.join(' ');
}
titleCase("I'm a little tea pot");
@NEbere
NEbere / longest_string.js
Created Feb 11, 2016
Return the length of the longest word in the provided sentence.
View longest_string.js
function findLongestWord(str) {
var strArray = str.toUpperCase().split(' ').sort();
var longest = 0;
for (var i = 0; i < strArray.length; i++) {
if (strArray[i].length > longest) {
longest = strArray[i].length;
}
}
return longest;
You can’t perform that action at this time.