data struct_strings Flashcards
How can i extract the first word of an unknown str?
cl(berry.slice(0, berry.firstIndexOf(‘ ‘));
how can i extract the last word of an unknown str?
cl(berry.slice(lastIndexOf(‘ ‘)+ 1))
How can you berry up the last index of a str?
const berry = str.slice( -1 )
I have a string of words that are all lowercase. I wanna print them with the first letters capped. How can i do this with a func?
create a func. with a param (refers to input string).
2. make a berry with param.split( ‘ ‘)
3. berry up an empty array to store results.
4. for ( i of PBS )
{ emptyArray.push( [ i ].toUpperCase( ) + i.slice( 1 ) }
5. return emptyArray.join( ‘ ‘)
a ragged undercored_str which must be turned to camelCase.
I wanna convert an arbitrary number of under scored string names into camel case names. The input is a single ragged string with the names separated by a \n. How can I do this?
- set up a func. 2. create a BERRY that splits(‘ _’).
- now that Ive split the text into arrays/rows. set up a for loop: for i in BERRY
- Clean up/berry up the 2 items in each array:
const [ first, second ] = counter.toLowerCase( ).trim( ).split( ‘_’); - berry up a template literal statement: const output =
${first}${second.relace(second[ 0 ], second[0].toUpperCase( ) )}
How can I call the last position of a duplicate string item?
CL(berry.lastIndexOf(‘ x ‘)
const leper = 'whamBamThankYou'; CL(leper.slice( 6 )
what does this print?
mThankyou
java slices everything before the given index number.
refering to the start and stop args of the slice method.
stop specifically. If the value is 7, is the value at index 7 eliminated?
No, the slice ends at 6.
const herper = 'lesionsInSeasons' CL(herper.slice( -2)) what does this prnt?
ns
A drunk user entered his name like this: ‘jOnaS.
Describe line by line, the func. that can clean it up.
const correctName = function (spelly) { const spellyLower = spelly.toLowerCase(); const spellyCorrect = spellyLower[0].toUpperCase() + spellyLower.slice(1); console.log(spellyCorrect); };
correctName(‘hfjhjYYYY’);
drunk user email entry: ‘ geIIoY@gMail.com \n
clean it up in one berry.
const cleanEmail = berry.toLowerCase().trim()
I can double up the same method on a berry:
TRUE OR FALSE?
TRUE: let price = '288,88E' let canprice = price.replace( ' E', '$').replace(' , ', ' .' )
How can i replace all occurences of a word in a string?
CL(berry.replace( /word/g, ‘ newWord’ )
There are 3 boolean methods we can use with strs. What are they?
berry. includes(‘x’)
berry. startsWith(‘x ‘)
berry. endsWith(‘x ‘)
What does this prnt?
CL(‘Danny Abubakar Asema’.split(‘ ‘);
[‘Danny’, ‘Abubakar’, ‘Asema’]
How can i split and berry up my name at the same time?
const [first, last] = ‘Daniel Tucket ‘.split(‘ ‘)
How can I prnt my berried fist and last names along with a ‘Mr.’ string? (No template literal):
let myName = [‘Mr.’ , first , last].join( ‘ ‘)
prnts: Mr. Daniel Tucket
describe a func. that would print a multiple word string given in lowercase, converted with the first letters of each word capped?
const getName = function (wretchedname) { const wretchedSplit = wretchedname.split(' '); const holder = []; for (const i of wretchedSplit) { holder.push(i[0].toUpperCase() + i.slice(1)); } return holder.join(' '); };
Give an example of padStart and PadEnd in one statement.
const padMe = berry.padStart(20, ‘ @ ‘).padEnd( 35, ‘ # ‘)
Please decribe the func. to mask a credit card number.
const hideNums = function (number) { const convertStr = number + ''; const exposed = convertStr.slice(-4); return exposed.padStart(convertStr.length, 'x'); };
repeat a str 10 times please.
const msg = 'ready when you are'; CL(msg.repeat(10 ))
How can I func. an html ‘button’?
- How can I berryup an html text input value?
- document.querySelector(‘button’).addEventListener(‘click’, function () {
- const text = document.querySelector(‘textarea’).value;
How can i use a for loop to loop an element as well as the index of said element at once?
for ( const [ i , el ] of berry.ENTRIES( ) )