Skip to content

Instantly share code, notes, and snippets.

View chaw-bot's full-sized avatar
👩‍🚀

Chawanzi Ng'uni chaw-bot

👩‍🚀
View GitHub Profile
const getCount = (str) => str.split('').filter((ele) => 'aeiou'.includes(ele)).length
@chaw-bot
chaw-bot / phoneNumber.js
Last active March 15, 2022 22:05
Given names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for is not found, print Not foun…
function processData(input) {
const inputArr = input.split('\n')
let num = parseInt(inputArr[0])
let contacts = {};
for (let i = 1; i <= num; i++) {
let temp = inputArr[i].split(' ')
contacts[temp[0]] = temp[1]
}
@chaw-bot
chaw-bot / processData.js
Last active February 18, 2022 21:50
Given a string, , of length that is indexed from to , print its even-indexed and odd-indexed characters as space-separated strings on a single line (see the Sample below for more detail). Note: is considered to be an even index. Example Print abc def
function processData(input) {
let splitInput = input.split('\n').slice(1);
splitInput.forEach((str) => {
let even = '';
let odd = '';
for(let i = 0; i < str.length; i++) {
i%2 === 0? even += str[i] : odd += str[i]
}
console.log(`${even} ${odd}`)
@chaw-bot
chaw-bot / eachCons.js
Last active February 18, 2022 21:48
Create a method each_cons that accepts a list and a number n, and returns cascading subsets of the list of size n, like so: each_cons([1,2,3,4], 2) #=> [[1,2], [2,3], [3,4]] each_cons([1,2,3,4], 3) #=> [[1,2,3],[2,3,4]]
function eachCons(array, n) {
let newArr = [];
let childArr;
for(let i = 0; i < array.length; i++) {
childArr = array.slice(i, n + i)
if(childArr.length === n) {
newArr.push(childArr)
}
}
return newArr
@chaw-bot
chaw-bot / spinWords.js
Last active February 18, 2022 21:46
Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present. Examples: spinWords( "Hey fellow warriors" ) => r…
function spinWords(string){
const arr = string.split(' ');
let result = '';
arr.map((str, i) => {
if (str.length >= 5){
arr[i] = str.split('').reverse().join('');
} else {
arr[i] = str;
}
result = arr.join(' ');
@chaw-bot
chaw-bot / simpleArraySum.js
Last active February 18, 2022 21:45
Given an array of integers, find the sum of its elements. For example, if the array , , so return . Function Description Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer. simpleArraySum has the following parameter(s): ar: an array of integers Input Format The first line contains…
function simpleArraySum(ar) {
let sum = 0
ar.map((num) => {
sum += num;
});
return sum;
}